Hi, I am getting errors with RTTI. In this program I have an Abstract base class with virtual function area() and two derived classes.
I defined a polymorphic function and passed the derived object as argument to it which has reference to the base class as argument. I used typeid opeator to find RTTI and execute a function which is not defined in the Abstract base class. But I am getting the error as follows.
class poly
{
public:
virtual void area(void)=0;
};
class square : public poly
{
void area(void ) { cout<<" area : square " ;}
virtual void display(void) { cout<<" I am square ";}
};
class rect : public poly
{
void area(void) { cout<<" area : rectangle ";}
};
void print(poly &abc)
{
abc.area();
if(typeid(abc)==typeid(square))
abc.display();
}
int main()
{
square s;rect r;
print(s);
}
Eroor : class poly doesnot have disp function as member
could you please help in finding out the reason behind this error