Why does compiler complain when I try to convert to a base-class?
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-05-21T12:38:11Z
Indexed on
2010/05/21
12:40 UTC
Read the original article
Hit count: 135
c++
|inheritance
class BaseClass
{
...
};
class SubClass
{
...
};
class MyApp
{
SubClass *pObject;
BaseClass *getObject()
{
return pOject;
}
};
I get a compiler error: error C2440: 'return' : cannot convert from 'SubClass *' to 'BaseClass *'
Why doesn't it work, surely you can automatically convert to a base-class without any casting?
© Stack Overflow or respective owner