G
Gary Wessle
Hi
I am trying to return a derived type pointer as the base type pointer
and the compiler is complaining, here is what I mean.
class A {
public:
A(){}
virtual void lol()=0;
};
class B : public A {
public:
B(): A() {}
void lol();
};
class C {
public:
C(){}
A* est(){
B b;
b.lol();
return &b;
}
};
filename.cpp:34: error: invalid conversion from ‘A*’ to ‘B*’
B and A habe "is-a" relationship, that is to say B is-a A, thus why it
is not working?
thanks
I am trying to return a derived type pointer as the base type pointer
and the compiler is complaining, here is what I mean.
class A {
public:
A(){}
virtual void lol()=0;
};
class B : public A {
public:
B(): A() {}
void lol();
};
class C {
public:
C(){}
A* est(){
B b;
b.lol();
return &b;
}
};
filename.cpp:34: error: invalid conversion from ‘A*’ to ‘B*’
B and A habe "is-a" relationship, that is to say B is-a A, thus why it
is not working?
thanks