Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Implicit cast to another class?


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
3 replies to this topic

#1 JamesMintram   Members   -  Reputation: 101

Like
0Likes
Like

Posted 01 April 2012 - 12:00 PM

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 Posted Image

Regards,
James Mintram

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 01 April 2012 - 02:41 PM

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

#3 JamesMintram   Members   -  Reputation: 101

Like
0Likes
Like

Posted 01 April 2012 - 03:23 PM

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

#4 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
1Likes
Like

Posted 01 April 2012 - 07:07 PM

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




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