"Base class undefined."

I've got an error:

error C2504: 'employee' : base class undefined.

I'm using Visual Studio 2010.

This is my first time working with inheritance in C++ and I can't figure out what I'm doing wrong. When I try to make a class that derives another, it says that the parent class is undefined, even though I have the header file of the parent class included. What could be the problem?

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
};

It says that both the student class and the employee2 class are undefined. Also, the employee2 class inherits a class called employee, which also gets the same error. What am I doing wrong?

EDIT: Here's my student.cpp file. All the other .cpp files that I'm getting errors with look similar to this one.

#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;
}

I don't believe you are getting an "x is undefinied" based upon the code you showed. Actually, it appears you are using #include wrong.

#include employee.h

should be

#include "employee.h"

Other than that, other than the missing employee class you mention, and manager not having getdata and " putdata in your example, you code will compile fine.


Make sure, there are empty spaces at the end of each file. Before compilation process the files are concatinated and your pragma could be deactivated because of sth like this:

}#pragma once

the '}' comes from the previously included file.

That could be a reason. Besides, the code looks, like it should be compilable.

链接地址: http://www.djcxy.com/p/95532.html

上一篇: 编译错误

下一篇: “基类未定义。”