T
Tony Johansson
Hello Experts!
I have been playing around a bit with this multiple inheritance and I wonder
why do I get a compile error
if I remove the virtual keyvord from the declaration of the Student class
and the Employee class.
I have removed all kind of data from all classes.
The compile error occur when I instansiate Person* p = new
TeachingAssistent;
The error I get is c:\Documents and
Settings\Tony\kau\cplusplus\test4\start.cpp(8): error C2594: 'initializing'
: ambiguous conversions from 'TeachingAssistent *' to 'Person *'
I know that if I have some data in the virtual base klass and not using the
virtual keyword I would get compile error because of having double defined
data in the TeachingAssistent() but I understand why so that's is no
problem.
#include <string>
using namespace std;
class Person
{
public:
Person() {}
string getName() const
{
return "rulle";
}
};
class Student : public Person
{
public:
Student() {}
};
class Employee : public Person
{
public:
Employee() {}
};
class TeachingAssistent : public Student, public Employee
{
public:
TeachingAssistent() {}
};
class GraduateAssistent : public TeachingAssistent
{
};
int main()
{
Person* p = new TeachingAssistent;
cout << p->getName() << endl;
}
I have been playing around a bit with this multiple inheritance and I wonder
why do I get a compile error
if I remove the virtual keyvord from the declaration of the Student class
and the Employee class.
I have removed all kind of data from all classes.
The compile error occur when I instansiate Person* p = new
TeachingAssistent;
The error I get is c:\Documents and
Settings\Tony\kau\cplusplus\test4\start.cpp(8): error C2594: 'initializing'
: ambiguous conversions from 'TeachingAssistent *' to 'Person *'
I know that if I have some data in the virtual base klass and not using the
virtual keyword I would get compile error because of having double defined
data in the TeachingAssistent() but I understand why so that's is no
problem.
#include <string>
using namespace std;
class Person
{
public:
Person() {}
string getName() const
{
return "rulle";
}
};
class Student : public Person
{
public:
Student() {}
};
class Employee : public Person
{
public:
Employee() {}
};
class TeachingAssistent : public Student, public Employee
{
public:
TeachingAssistent() {}
};
class GraduateAssistent : public TeachingAssistent
{
};
int main()
{
Person* p = new TeachingAssistent;
cout << p->getName() << endl;
}