Multiple Inheritance Problem

Started by
0 comments, last by imitation 20 years ago
I''ve recently come up against a problem with angelscript and my engine, where i''ve used multiple inheritance with an object, eg. Door, and have not been able to register a method for it (using RegisterObjectMethod). If Door inherits from Object + Scriptable, the compiler complains:

error C2440: ''type cast'' : cannot convert from ''void (__thiscall Door::*)(int)'' to ''void (__thiscall asCDummy::*)(void)''
        Pointers to members have different representations; cannot cast between them
 
The same goes for if Scriptable inherits from Object, and Door inherits from Scriptable. However, if Door just inherits from Object, all is well, it compiles fine. Is this a limitation in angelscript or c++? or am I just going about it incorrectly? and is there a way around it, without having to redesign all my classes?
Advertisement
I''m not sure, but I think you are trying to take the pointer of a virtual method, which is different from a fixed method because it needs to do a lookup in the virtual table.

AngelScript doesn''t support virtual methods yet, and even if it did you would probably have trouble with the multiple inheritance, as it requires yet another step when calling the methods.

I''m afraid that at the moment your best choice is to write proxy functions that will be able to figure out the correct way of calling the object methods. Example:

void Door_DoSomething(Door *door){  door->DoSomething();}engine->RegisterObjectMethod("door", "void DoSomething()", asFUNCTION(Door_DoSomething), asCALL_CDECL_OBJLAST); 


The other solution would be to redesign your classes, so that they don''t use virtual methods.

In the future I''m hoping to have support for virtual functions in AngelScript, but I think I will not be able to find a good solution for multiple inheritance because each compiler does it a different way.

Regards,
Andreas

__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement