Plorg.h:
#include <string>
#ifndef PLORG_H
#define PLORG_H
class Plorg{
private:
string name;
int CI;
public:
Plorg();
Plorg(const string & n,int x=50);
~Plorg();
void ChangeID(int CIaux);
void Report() const;
};
#endif PLORG_H
Plorg.cpp:
#include <iostream>
#include <string>
#include "Plorg.h"
using namespace std;
Plorg::Plorg(){
name="Plorga";
CI=50;
};
Plorg::Plorg(const string & n,int CIaux=50){
name=n;
CI=CIaux;
};
void Plorg::ChangeID(int CIaux){
CI=CIaux;
};
void Plorg::Report() const {
cout << "My name is " << name << "!" <<endl;
cout << "MY CI is" << CI << "." ;
};
Plorg::~Plorg(){
cout << "Bye,human" ;
};
I get this error,thoguh:
Error 11 error C2065: 'name' : undeclared identifier c:\\users\\work\\documents\\visual studio 2012\\projects\\book\\firstclass\\firstclass\\plorg.cpp 7 1 firstclass
So,what should I do?
string
is really std::string
:
class Plorg{
private:
std::string name;
// ^^^
public:
Plorg();
Plorg(const std::string& n, int x=50);
// ^^^
As an aside, you should favour the constructor initialization list, and don't put the default parameter value in the implementation:
Plorg::Plorg(const std::string & n, int CIaux) : name(n), CI(CIAux) {}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.