When I run the following code:
#include <iostream>
class Shape{
public:
};
class Square:public Shape
{
public:
};
class Circle:public Shape
{
double r;
public:
void SetRadious(double r)
{
std::cout << "R value:" << this->r <<std::endl;
this->r=r;
}
};
int main() {
Shape * s = new Square();
Circle* c= dynamic_cast<Circle*>(s);
c->SetRadious(3.0);
return 0;
}
I get an error saying:
'Shape' is not polymorphic
I read about that and found out that I need to write some virtual function But have 2 questions:
1) Why is this necessary, it just doen't make sense to require a virtual function.
2) In this case many said that I need virtual d'tor But why the default one won't be totally fine, what's the difference between default d'tor and the default one?