Cast

Why can not I convert the object of a derived class to a base class without using pointers?

1
2
3
4
5
6
7

Derived o; 
Base i = (Base)o; /*/ Error /*/

Derived* o; 
Base* i = (Base*)o; /*/ Ok /*/
It should "work" if you have used public inheritance and you have not disabled the copy/move constructors.
Duplicate of http://www.cplusplus.com/forum/beginner/126132/ . Please don't spam the forum with multiple threads for the same topic.
Topic archived. No new replies allowed.