【发布时间】:2013-08-18 07:29:44
【问题描述】:
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" ;
};
我得到了这个错误,虽然:
错误 11 错误 C2065:“名称”:未声明的标识符 c:\users\work\documents\visual studio 2012\projects\book\firstclass\firstclass\plorg.cpp 7 1 firstclass
那么,我该怎么办?
【问题讨论】:
-
您应该使用构造函数初始化程序列表。我也不认为这是你的第一个错误。
-
您在“Plorg.h”中的成员都缺少
std::命名空间限定符。不要将using namespace std;放在标题中。修复成员和构造函数参数变量声明。
标签: c++ class implementation