Is it safe to use static_cast in this polymorphic scenario?-Collection of common programming errors
I have a type heirarchy:
class Object {
...
};
class Node : public Object {
...
};
class Leaf : public Object {
...
};
class Something : public Node {
...
};
class SomethingElse : public Leaf {
...
};
In other words, absolutely every class inherits Object either directly or indirectly.
The constructor for every object is in the following format:
ClassType(Object * parent)
However, by design only a Node can be a parent, while a Leaf is a terminating node;
In the moment, in every constructor I am doing the following:
Node * p = dynamic_cast(parent);
if (p) p->adopt(this);
else qDebug()