【发布时间】:2018-05-07 19:57:37
【问题描述】:
我的问题是如何将类放在不同的文件中并使程序运行?当我尝试在 Student.h 文件中构建和运行它时出现错误 ---> 字符串没有命名类型
main.cpp:
#include <iostream>
#include "Student.h"
using namespace std;
int main()
{
Student *a;
a = new Student(1,"Astudent");
a->printStudent();
system("PAUSE");
return 0;
}
学生.h:
#ifndef STUDENT_H
#define STUDENT_H
class Student
{
private:
int id;
string name;
public:
Student(int id,string name);
void printStudent();
};
#endif
学生.cpp:
#include <iostream>
#include "Student.h"
using namespace std;
Student::Student(int id,string name)
{
this->id = id;
this->name = name;
}
Student::printStudent()
{
cout << id << "." << name << endl;
}
【问题讨论】:
-
您没有在头文件中包含任何包含...
-
您如何尝试构建和运行它?
标签: c++