Advertisement

Assign object handle to array element

Started by October 11, 2013 06:58 AM
1 comment, last by zexee 11 years, 1 month ago

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?

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

Advertisement

I see, thank you very much!

This topic is closed to new replies.

Advertisement