• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Multiple Inheritance Problem

## 1 post in this topic

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?
0

##### Share on other sites
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
0