T
Tony Johansson
Hello experts!
I have a small program that is using multiple inheritance.
There are 4 classes involved
I get 4 compile error that I can't figure out why.
It's this row which is located in the main program see below that is causing
these compile errors.
cout << p->getName() << endl;
Here is the first compile error the other might be a consequesce of the
first one.
c:\Documents and Settings\Tony\kau\cplusplus\test4\start.cpp(13): error
C2446: '<' : no conversion from 'std::vector<_Ty>::size_type (__thiscall
std::vector<_Ty>::* )(void) const' to 'int'
with
[
_Ty=Person *
]
Here are all the class definitions
*********************
#include <string>
using namespace std;
class Person
{
public:
Person(string nn = "default") : name(nn) {}
string getName() const
{
return name;
}
private:
string name;
};
class Student : public virtual Person
{
public:
Student(string nn="default") : Person(nn) {}
};
class Employee : public virtual Person
{
public:
Employee(string nn="default") : Person(nn) {}
};
class TeachingAssistent : public Student, public Employee
{
public:
TeachingAssistent(string nn="default") : Person(nn) {}
};
Here is main program
****************
#include <vector>
#include "person.h"
#include <iostream>
using namespace std;
int main()
{
vector<Person *> p;
p.push_back(new Student);
p.push_back(new Employee);
p.push_back(new TeachingAssistent);
for(int i=0; i < p.size; i++)
cout << p->getName() << endl;
return 0;
}
Many thanks
//Tony
I have a small program that is using multiple inheritance.
There are 4 classes involved
I get 4 compile error that I can't figure out why.
It's this row which is located in the main program see below that is causing
these compile errors.
cout << p->getName() << endl;
Here is the first compile error the other might be a consequesce of the
first one.
c:\Documents and Settings\Tony\kau\cplusplus\test4\start.cpp(13): error
C2446: '<' : no conversion from 'std::vector<_Ty>::size_type (__thiscall
std::vector<_Ty>::* )(void) const' to 'int'
with
[
_Ty=Person *
]
Here are all the class definitions
*********************
#include <string>
using namespace std;
class Person
{
public:
Person(string nn = "default") : name(nn) {}
string getName() const
{
return name;
}
private:
string name;
};
class Student : public virtual Person
{
public:
Student(string nn="default") : Person(nn) {}
};
class Employee : public virtual Person
{
public:
Employee(string nn="default") : Person(nn) {}
};
class TeachingAssistent : public Student, public Employee
{
public:
TeachingAssistent(string nn="default") : Person(nn) {}
};
Here is main program
****************
#include <vector>
#include "person.h"
#include <iostream>
using namespace std;
int main()
{
vector<Person *> p;
p.push_back(new Student);
p.push_back(new Employee);
p.push_back(new TeachingAssistent);
for(int i=0; i < p.size; i++)
cout << p->getName() << endl;
return 0;
}
Many thanks
//Tony