Why cannnot derived class pointer point to a base class object?
Hi,Pleaseeee... explain me why cannot the derived class pointer point to a base class object. I know that Base class pointer can point to a derived class object.Thanks & Regards,Vig....
[224 byte] By [
vignesh_cn] at [2007-11-26 10:39:08]

# 1
Example:
class Base
{ public: void foo(); } * pBase;
class Derived : public Base
{ public: void bar(); } * pDerived;
Now, what would happen if you assign pDerived = new Base() and then call pDerived->bar()?By forbidding such an assignment, compiler prevents you from writing error-prone code.