I understand the whole polymorphism thing, the ability to call functions that are dervied from a base class. BUt right now I'm designing a scene graph and I have a quick question. Say I have a base calss that is only designed to be a base system. It has a couple virtual functions you can call i.e. draw... But could I do this?
Code: Select all
//base_object is the base object, mesh_object has room for point data.
//mesh_object is derived from base_object.
void createnewmesh(char *name, char *filename, base_object* parent)
{
base_object* mesh_ob = new mesh_object(name, filename);
parent->attach_child(mesh_ob);
}
From what I know, this should create a mesh object the is attached to a the parent it is assigned to (like a gun to a character, another mesh object.) If there is anything wrong with this please inform me before I design this wrong. It's much easier to make the right choice at the beggining than to have the back track back to the problem and then change all the source code i affects.