Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

implicit casting between reference types in script


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 iraxef   Members   -  Reputation: 318

Like
0Likes
Like

Posted 16 December 2013 - 01:56 PM

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, 16 December 2013 - 01:56 PM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 16 December 2013 - 07:10 PM

You've registered the ref casts correctly. The problem is as you suspected that the implicit cast is not done in this case.

Instead you need to register the inherited methods in the derived class too.

This is documented here: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_class_hierarchy.html#doc_adv_class_hierarchy_2
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 iraxef   Members   -  Reputation: 318

Like
0Likes
Like

Posted 16 December 2013 - 08:04 PM

Thank you very much - I ended up doing something similar.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS