Game Development Community

Combining class hierarchies

by Don Harvey · in Torque Game Engine · 01/29/2006 (9:27 am) · 1 replies

I have a question about TGE requirements as it relates to class hierarchies. I have a series of classes that's heavily dependent upon a non-Torque base class. Several of the classes in this hierarchy needs to be derived from my base as well as a TGE class. Here's what I've done with one of these classes:

Torque Item
MyBase /
\ /
\ /
MyItem

My question is - should I derive MyBase from ConsoleObject or SimObject OR is it ok to use an independant base class. I get GPF's after I made this change and I suspect that TGE can't properly instanciate a MyItem unless I register it with the engine. I should also mention MyBase is an abstract class.

If I am required to derive MyBase from a TGE class, do I need to derive all the classes upstream of MyItem virtually (in other words, do I have to have "class MyBase : virtual public SimObject" and change class Item to derive virtually, etc.?)

#1
02/22/2006 (6:55 am)
You can multiply inherit from different classes as long as you strictly avoid any possibility of the "diamond problem", where there would be multiple paths of inheritence of the same functionality. Note this is standard C++, not anything specific to Torque. The SceneObject class (/engine/sim/sceneObject.h) is an example of multiple inheritence within Torque--it inherits from NetObject and Container::Link.