为了账号安全,请及时绑定邮箱和手机立即绑定

分文件类外定义为什么会报错啊?

按照老师的代码写的,不知道为什么报错了,报的错也看不懂QAQ。但是如果我在头文件上加#include<...>那几行 就能正常运行了,为什么啊?这样做对不对啊?

575eb06c00017af403870162.jpg

575eb06d00012b8d05000223.jpg

575eb06d0001bd4205000296.jpg


正在回答

2 回答

第一个#我也不太清楚具体含义,第二个#要加上,因为你的类中有string类型的数据,第3行是命名空间,因为你用了打印数据的函数(方法),而那个方法是属于std这个指令集(方法库)的

1 回复 有任何疑惑可以回复我~

1>------ 已启动生成: 项目: text, 配置: Debug Win32 ------

1>生成启动时间为 2016/11/23 16:46:32。

1>InitializeBuildStatus:

1>  正在创建“Debug\text.unsuccessfulbuild”,因为已指定“AlwaysCreate”。

1>ClCompile:

1>  demo.cpp

1>c:\users\john\desktop\text\demo.cpp(9): error C2065: “Teacher”: 未声明的标识符

1>c:\users\john\desktop\text\demo.cpp(9): error C2146: 语法错误: 缺少“;”(在标识符“t”的前面)

1>c:\users\john\desktop\text\demo.cpp(9): error C2065: “t”: 未声明的标识符

1>c:\users\john\desktop\text\demo.cpp(10): error C2065: “t”: 未声明的标识符

1>c:\users\john\desktop\text\demo.cpp(10): error C2228: “.setName”的左边必须有类/结构/联合

1>          类型是“'unknown-type'”

1>c:\users\john\desktop\text\demo.cpp(11): error C2065: “t”: 未声明的标识符

1>c:\users\john\desktop\text\demo.cpp(11): error C2228: “.setGender”的左边必须有类/结构/联合

1>          类型是“'unknown-type'”

1>c:\users\john\desktop\text\demo.cpp(12): error C2065: “t”: 未声明的标识符

1>c:\users\john\desktop\text\demo.cpp(12): error C2228: “.setAge”的左边必须有类/结构/联合

1>          类型是“'unknown-type'”

1>c:\users\john\desktop\text\demo.cpp(13): error C2065: “t”: 未声明的标识符

1>c:\users\john\desktop\text\demo.cpp(13): error C2228: “.getName”的左边必须有类/结构/联合

1>          类型是“'unknown-type'”

1>c:\users\john\desktop\text\demo.cpp(13): error C2065: “t”: 未声明的标识符

1>c:\users\john\desktop\text\demo.cpp(13): error C2228: “.getGender”的左边必须有类/结构/联合

1>          类型是“'unknown-type'”

1>c:\users\john\desktop\text\demo.cpp(13): error C2065: “t”: 未声明的标识符

1>c:\users\john\desktop\text\demo.cpp(13): error C2228: “.getAge”的左边必须有类/结构/联合

1>          类型是“'unknown-type'”

1>c:\users\john\desktop\text\demo.cpp(14): error C2065: “t”: 未声明的标识符

1>c:\users\john\desktop\text\demo.cpp(14): error C2228: “.teach”的左边必须有类/结构/联合

1>          类型是“'unknown-type'”

1>

1>生成失败。

1>

1>已用时间 00:00:01.46

========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
C++远征之封装篇(上)
  • 参与学习       103381    人
  • 解答问题       732    个

封装--面向对象的基石,本教程力求帮助小伙伴们即学即会

进入课程

分文件类外定义为什么会报错啊?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号