Advertisement Jump to content
Sign in to follow this  
iraxef

implicit casting between reference types in script

This topic is 1858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the following in C++:

class Base
{
public:
    void Foo() { ... }
};

class Derived : public Base
{
};


I then bind these types as follows:

RegisterObjectType("Base",     0, asOBJ_REF | asOBJ_NOCOUNT);
RegisterObjectType("Derived",  0, asOBJ_REF | asOBJ_NOCOUNT);

RegisterObjectMethod("Base", "void Foo()", asMETHODPR(Base, Foo, (), void), asCALL_THISCALL);

RegisterObjectBehaviour("Base", asBEHAVE_REF_CAST, "Derived@ f()", asFUNCTION((refCast<Base,Derived>)), asCALL_CDECL_OBJLAST);
RegisterObjectBehaviour("Derived", asBEHAVE_IMPLICIT_REF_CAST, "Base@ f()", asFUNCTION((refCast<Derived,Base>)), asCALL_CDECL_OBJLAST);

Then in script I have the following:

void main(Derived& d)
{
  d.Foo();
}

I expect the registered implicit conversion to apply to 'd' and call (in C++) d.Foo(), which should resolve to Base's Foo(). However, I get the following compilation error:

 

No matching signatures to 'Derived::Foo()'

 

Am I doing anything wrong with how I'm registering the implicit cast? Or would it only take effect for assignment/function params/etc and not what I'm trying to do?

 

Thank you very much.

Edited by iraxef

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!