Advertisement

Implicit cast to another class?

Started by April 01, 2012 06:00 PM
2 comments, last by WitchLord 12 years, 8 months ago
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
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 - Tower - free puzzle game

Advertisement
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
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 - Tower - free puzzle game

This topic is closed to new replies.

Advertisement