Class A is abstract class. I would like to call the same method from different subclasses. There are no errors from compiler, but program crashes.
class A
{
protected:
MA* array1[10]; //static array of pointers to some other class
int st;
public:
...
virtual string ToString() const
{
stringstream ss;
for(int i=0;i<st;i++)
{
ss<<array1[i]->getname()<<",";
}
return ss.str();
}
};
ToString method works in both classes A and B but doesn't work in class C
class B: public A
{
private:
...
public:
string ToString() const
{
return A::ToString();
}
};
class C: public A
{
private:
...
public:
string ToString() const
{
return A::ToString();
}
};
This is main:
A* P[5];
P[0]=new B();
P[1]=new C();
P[0]->ToString();
P[1]->ToString();