& vs. &in: There is no copy operator for this type available.

Started by
2 comments, last by WitchLord 15 years, 3 months ago
Hi, I recently tried to register the following function: void makeDynamic(const PhysicsObject *object). If I choose the signature "void makeDynamic(const PhysicsObject &in)" I will get the error "There is no copy operator for this type available." when I call the function via angelscript. If however I choose the the signature "void makeDynamic(const PhysicsObject &" all works well. "void makeDynamic(const PhysicsObject @" seems to be ok to. I don't really know what is happening so I am asking out of curiosity. I believe I use &in on all my other function registrations. Just wondering if there is an easy explanation for this. Thanks for the help.
Advertisement
With &in you're telling AngelScript that the reference is only for input. For that reason AngelScript may make a copy of the object, in order to guarantee that modifications to the object within the function doesn't reflect on the original object. Since the reference is also const AngelScript will only make the copy if the reference isn't to a local variable.

With just & or with @ the reference is both input and output, so in this case AngelScript sends the true object. The difference between & and @ is that the reference always points to an object, where-as the handle may be null (similar to & and * in C++).

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I see.
I used &in as an argument several times although it is a * in my c++ code. It is also the first time I got such an message. Maybe I should use @ more often. Thanks for the info.
'const type &in' is recommended for complex value types, as most of the time AngelScript can avoid making the copy of the object.

'@' or just '&' is recommended for reference types, unless you really need to prevent the called function from changing the object.



This is an area of AngelScript that I have plans to improve in a future version. It works the way it is, but it can be greatly simplified without loosing performance.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement