#include "stdafx.h"
#include<iostream>
using namespace std;
class Shape
{
public:
virtual void fun()
{
cout<<"in base"<<endl;
}
};
class Square:public Shape
{
public:
void fun()
{
cout<<"in Square"<<endl;
}
};
class Circle:public Shape
{
public:
void fun()
{
cout<<"in Circle"<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Shape *s=new Shape();
s->fun();
Circle *Sq=(Circle *)s;
Sq->fun();
system("pause");
return 0;
}
Output:
In BAse
In BAse
can anyone tell me why it didn't called the fun() of Circle ,as i type casted the Shape object to circle.
TIA