Jump to content
  • Advertisement
Sign in to follow this  
B_old

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

This topic is 3597 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

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
'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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!