Skip to main content
GameDev.net gamedev.net
🔒 Locked

Implicit cast to another class?

Started by jamesmintram Apr 1, 2012 at 6:00 PM 2 replies 1.6k views
Original Post
jamesmintram
jamesmintram
Hello,

Is it possible with angelcode script to create a class that can be implicitly cast to another class?
Here is an example of usage (not written in Angelcode but you should get the idea)


class node
{
};

class anotherNode
{
public:
operator node () { return m_node; }

protected:
node m_node;
};

void needsNode ( node item ) {}

anotherNode someItem;
needsNode ( someItem ); //Here we call a function that needs a node class so someItem is implicity cast


I should also note that I am wanting to do this with references/handles not concrete objects.

Hopefully you can see what I am trying to achieve smile.png

Regards,
James Mintram
WitchLord
WitchLord
No, this is something that is currently unavailable.

You can do it for registered classes by registering the asBEHAVE_IMPLICIT_REF_CAST, but this is not available for script classes.

Can't anotherNode inherit from the node class, rather than keep it as a member? If it inherited from the node class, then the implicit cast would work.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
jamesmintram
jamesmintram
I cannot inherit from Node as it is a registered c++ class. I was hoping by wrapping it in a script class that would be inmplictly cast to a Node which would achieve the same effect for me as inheriting directly from Node.

Is there another way to achieve what I am trying to do?

If not is it likely some feature like this would be implemented in the near future?

Regards,
James Mintram
WitchLord
WitchLord
Unfortunately not. The best that can be done at the moment is to provide a method to explicitly return the inner node.

I'll study the case and see what I can implement to support implicit cast operators in the script language.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.