hello,
I have a class Node, and another one called TransformationNode : public Node
in a function called updateTransform, I iterate trough a vector in the base class vector<Node*> nodes.
In the base class there are no such functions, lets say void addVec(); and TransformationNode* updateTransfrom();
and updateTransfrom() is something like this...
1 2 3 4 5 6 7 8 9 10 11
|
TransformationNode* updateTransfrom() {
auto beg = nodes.begin();
auto end = nodes.end();
while(beg != end) {
TransformationNode* tmp = static_cast<TransformationNode*>(*beg);
tmp->addVec();
beg++;
}
return tmp;
}
|
I don't want to do type cast alot, is this the only way of doing this ? How do I tell my compiler that, "nodes" vector is already containing TransformationNode* ?
And I have an other very similar issue,
I have a functon called Graph* getGraph() in base, and a member Graph* mGraph
However, implementation in TransformationNode class must be somethig like this SceneGraph* getGraph(); and the member mGraph's type also must be TransformationNode*
I get around this issue by type casting the pointer returned by getGraph() to a TransformationNode* pointer
I wanted to know if my design is problematic or there is a better solution to these kind of problems.
And if you know any, good books or articles about this kind of usage of the c++ and object oriented design
thank you for taking your time.