分文件定义出错
同文件定义能通过,但是分文件定义函数时提示:void Teacher::setName(string _name);这一行Teacher不是类或命名空间名称,但是我已经包含Teacher.h头文件了,而且写程序时Teacher这个单词也已经变色了啊,这到底是为什么???????
同文件定义能通过,但是分文件定义函数时提示:void Teacher::setName(string _name);这一行Teacher不是类或命名空间名称,但是我已经包含Teacher.h头文件了,而且写程序时Teacher这个单词也已经变色了啊,这到底是为什么???????
2017-01-23
//Teacher.h文件 #include <string> using namespace std; class Teacher { public: void setName(string _name); string getName(); void setGender(string _gender); string getGender(); void setAge(int _age); int getAge(); void study(); private: string m_strName; string m_strGender; int m_iAge; }; //Teacher.cpp文件 #include "Teacher.h" #include<iostream> #include "stdafx.h" using namespace std; void Teacher::setName(string _name) { m_strName = _name; } string Teacher::getName() { return m_strName; } void Teacher::setGender(string _gender) { m_strGender = _gender; } string Teacher::getGender() { return m_strGender; } void Teacher::setAge(int _age) { m_iAge = _age; } int Teacher::getAge() { return m_iAge; } void Teacher::study() { cout << " let`s study..." << endl; } //demo.cpp #include "stdafx.h" #include"Teacher.h" #include <iostream> #include<String> using namespace std; int main() { Teacher A; A.setName("Alex"); A.setGender("male"); A.setAge(19); cout << A.getName() << "" << A.getGender() << "" << A.getAge() << endl; A.study(); return 0; }
举报