I tried to convert by "dynamic_cast" in the following way:
#include <iostream>
class Shape {
//....
};
class Square: Shape {
//....
};
class Circle: Shape {
//....
};
int main() {
Circle cr;
Shape* sh = &cr; // ERROR1
Square* psq = dynamic_cast<Square*>(sh); //ERROR2
return 0;
}
And I get error messages:
ERROR1: 'Shape' is an inaccessible base of 'Circle'
ERROR2: cannot dynamic_cast 'sh' (of type 'class Shape*') to type 'class Square*' (source type is not polymorphic)
Can someone explain why I get these errors?