C++ 程序问题 高手帮忙改改

xxcpsdht 2011-03-19 03:24:25

#include <iostream>
#include <string>
using namespace std;

class CStudent{
public:
CStudent();
CStudent(string s);
string sName; // 姓名
string sNativePlace; // 籍贯
string sStudentID; // 学号
string sInfo;
int iAge; // 年龄
int iScorePlace; // 排名
void Display(void);
private:
string sStyle;
};

CStudent::CStudent(string s){
sStyle = s;
}

void CStudent::Display(void){
cout << sStyle << "信息: " << endl;
cout << " --> 姓名: " << sName << endl;
cout << " --> 籍贯: " << sNativePlace << endl;
cout << " --> 学号: " << sStudentID << endl;
cout << " --> 年龄: " << iAge << endl;
cout << " --> 排名: " << iScorePlace << endl;
if (sStyle == "导师")
cout << " --> 导师信息: " << sInfo << endl;
cout << endl;
}

class CMaster: public CStudent{
public:
CMaster();
CMaster(string s);
};

int main(void){
CMaster master("导师");
master.iAge = 22;
master.iScorePlace = 1;
master.sInfo = "QQ 272399954";
master.sName = "X.Rabbit";
master.sNativePlace = "HongKong";
master.sStudentID = "ID Number 1";
master.Display();
system("PAUSE>NUL");
return 0;
}

错误提示: 无法解析的外部符号
error LNK2001: unresolved external symbol "public: __thiscall CMaster::CMaster(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0CMaster@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>D:\XXX\Documents\Visual Studio 2010\Projects\Temp\Release\Temp.exe : fatal error LNK1120: 1 unresolved externals
...全文
69 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengzhixi 2011-03-19
  • 打赏
  • 举报
回复
CMaster(string s):CStudent(s){}
KID_coder 2011-03-19
  • 打赏
  • 举报
回复
CStudent(); 这里也是
witwolf 2011-03-19
  • 打赏
  • 举报
回复
CMaster();
CMaster(string s);
没有定义,你要实现它
KID_coder 2011-03-19
  • 打赏
  • 举报
回复
class CMaster: public CStudent{
public:
CMaster();
CMaster(string s);
};
这两个构造函数只声明,没有定义
LinuxBirdMan 2011-03-19
  • 打赏
  • 举报
回复
把定义添加上去就OK了。。。
LinuxBirdMan 2011-03-19
  • 打赏
  • 举报
回复
你没定义这个类的构造函数CMaster,你只给出申明。。。

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧