• 12
• 12
• 9
• 10
• 13

# Implicit cast to another class?

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

## Recommended Posts

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

Regards,
James Mintram

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

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