Quick question on Polymorphism...

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
dbzprogrammer
Posts: 5
Joined: Sat Nov 13, 2004 4:52 am

Quick question on Polymorphism...

Post by dbzprogrammer »

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.
Image
T101
Posts: 44
Joined: Thu Jul 29, 2004 4:41 pm

Post by T101 »

Looks fine to me. Bog-standard polymorphism.

Of course you cannot call a function that is not also defined in the base class unless you cast to the specific class - but I think you've got that.

With attached items you might want to get the relative position using bones or offsets.
Post Reply