“基类未定义。”
我有一个错误:
错误C2504:'employee':基类未定义。
我正在使用Visual Studio 2010。
这是我第一次使用C ++继承,我无法弄清楚我做错了什么。 当我尝试创建一个派生另一个类的类时,它说父类是未定义的,即使我已经包含父类的头文件。 可能是什么问题呢?
Main.cpp的:
#include <string>
#include <iostream>
using namespace std;
#include "manager.h"
int main()
{
manager ian;
ian.getdata();
ian.putdata();
return 0;
}
Manager.h:
#pragma once
#include "employee2.h"
#include "student.h"
class manager : private employee2, private student //Error happens here
{
//Stuff
};
Student.h:
#pragma once
class student
{
//Stuff
};
Employee2.h:
#pragma once
#include "employee.h"
class employee2 : employee
{
//Stuff
};
它表示学生类和employee2类都是未定义的。 此外,employee2类继承了一个名为employee的类,它也会得到相同的错误。 我究竟做错了什么?
编辑:这是我的student.cpp文件。 所有其他.cpp文件,我得到的错误看起来类似于这个。
#include "student.h"
void student::getedu(){
cout << "Enter name of school or university: ";
cin >> school;
cout << "Enter highest degree earned n";
cout << "(Highschool, Bachelor's Master's, PhD)";
cin >> degree;
}
void student::putedu() const{
cout << "n School or university: " << school;
cout << "n Highest degree earned: " << degree;
}
根据你展示的代码,我不相信你会得到“x未定论”。 其实,看起来你正在使用#include
错误。
#include employee.h
应该
#include "employee.h"
除此之外,除了你提到的失踪employee
类以外, manager
没有getdata
和“ putdata
”,你的代码将会很好地编译。
确保每个文件末尾都有空格。 在编译过程之前,这些文件是连接在一起的,因此你的编译指示可能会失效,因为:
}#pragma once
'}'来自之前包含的文件。
这可能是一个原因。 此外,代码看起来像它应该是可编译的。
链接地址: http://www.djcxy.com/p/95531.html