Jump to content
  • Advertisement
Sign in to follow this  
IndependentHat

Curious compiler warning

This topic is 2863 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 get an odd compiler warning
"Warning: A non-const method is called on a temporary object. Changes to the object may be lost."
with the following code...

NxVec3 mouse(getMouseX(),getMouseY(),0.0f);
Ray ray;
ray.pos = spriteEngineUnproject(mouse);
mouse[2] = 1.0f;
ray.dir = spriteEngineUnproject(mouse) - ray.pos;
ray.len = 2*spriteEngineDrawDistance;
ray.castRay();


Changing code to this removes the warning:

NxVec3 mouse(getMouseX(),getMouseY(),0.0f);
Ray ray;
ray.pos = spriteEngineUnproject(mouse);
mouse[2] = 1.0f;
ray.dir = spriteEngineUnproject(mouse);
ray.dir -= ray.pos;
ray.len = 2*spriteEngineDrawDistance;
ray.castRay();


ray.dir and ray.pos are registered as a value type NxVec3 and spriteEngineUnproject returns a value type NxVec3.

Also, it would be really nice in the future if I could use SpriteEngine::method/property instead of generating new global names for statics : /

Share this post


Link to post
Share on other sites
Advertisement
The opSub method of the NxVec3 is probably not registered as a const method as it should.

What happens is that spriteEngineUnproject() returns the NxVec3 object which is stored in a temporary variable. Then the opSub method is called (for the - operation). Since the opSub method is not const, the compiler has no way of knowing that this is not actually going to modify the NxVec3 object, thus it is giving you this warning.

I'll see if I can improve the message though, to make it a little more clear as to what it is referring to.



Namespaces will be supported in the future.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!