Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now
- - - - -

Assign object handle to array element

4: Adsense

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

#1 zexee   Members   

118
Like
0Likes
Like

Posted 11 October 2013 - 12:58 AM

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?

 



#2 Andreas Jonsson   Moderators   

4624
Like
0Likes
Like

Posted 11 October 2013 - 08:00 AM

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.


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 zexee   Members   

118
Like
0Likes
Like

Posted 11 October 2013 - 11:46 PM

I see, thank you very much!






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.