Jump to content
  • Advertisement
Sign in to follow this  
zexee

Assign object handle to array element

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am a bit confused about how to use object handle. Here is the code example I was trying to compile with the add-on array:

class Obj {
  int x;
};

void main() {
  array<Obj@> a(3);
  Obj o;
  o.x = 10;
  a[0] = @o;
}

The compile error is "Can't implicitly convert from 'Obj@const&' to 'const Obj&'." for the assign line.

What is the correct way of doing that?

 

Share this post


Link to post
Share on other sites
Advertisement

The @ symbol goes on the left hand expression to signal a handle assignment. The right hand expression can also be pre-fixed with @, but that is optional.

 

 @a[0] = o;

 

Without the @ symbol the assignment will be done by value, i.e. calling the Obj's opAssign operator.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!