I have a problem with C++ vector understanding: an object I get from vector is always a base abstract class and not a derived class that was added to it.
I have a vector:
vector<SceneNode*> children;
Where SceneNode is an abstract class with pure virtual functions.
I add an instance of ImageSceneNode (that is derived from SceneNode) to this vector:
lib::ImageSceneNode node(static_cast<TextureAsset*>(test)); sceneManager.getRoot()->addChild(&node);
Where addChild function is:
void SceneNode::addChild(SceneNode* child) noexcept {
this->children.push_back(child);
}
- Later when I iterate the vector the object inside is an instance of SceneNode and fails with a "pure virtual function" call error:
Can you please help, thank you!