如果是多个.c 和.h文件编程是不是要把这些文件都放到一个文件夹中呢,我的代码总是提示 undefined reference to `Student::Student()'
//这是Student.cpp文件
#include"Student.h"
#include<iostream>
using namespace std;
Student::Student()
{
cout<<"hello mook"<<endl;
}
void Student::setAge(int _age)
{
age = _age;
}
int Student::getAge()
{
return age;
}
//下面是Student.h 文件
class Student
{
public:
Student();
void setAge(int _age);
int getAge();
private:
int age;
};
//下面是main.cpp 文件
#include <iostream>
#include"Student.h"
using namespace std;
int main()
{
Student *p = new Student();
p->setAge(100);
cout<<p->getAge()<<endl;
delete p;
p = NULL;
return 0;
}