I created the following classes:
class A
{
};
class B :public A
{
public:
void p()
{
cout<<"P";
}
};
class C:public A
{
};
I tried to access the member function p() defined in class B using class C's dynamically created object.
C* c = new C();
((B*)c)->p();
I was expecting that program will crash as there in no object of class B.But it worked and produced output p.How does it work?