Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Draigan

consts and stuff

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


  
    Vector3& Center ();
    const Vector3& Center () const;
  
How would the compiler know which version to use? I didn''t previously know that this was possible but I''ve seen Eberly use it in his Magic Software code.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
one is for retrieving, the other for setting:

minZ = bOBB.Center().z - bOBB.Extent(2); // retrieving

bBox.Center().x = min.x + dX*0.5f; // setting


the retrieval is done via the const version of the function.

at least that''s the way i use ''em.

Share this post


Link to post
Share on other sites
If the object being operated-on is a const object, it can only use the second. If the object is non-const, my compiler chooses the first. I don''t believe the compiler can use the return value to determine the function type (IANALL), so I think it just calls the function that corresponds to the type of object.

Example:

  
class C
{
public:
C &foo ()
{
return *this;
}
const C &foo () const
{
return *this;
}
};

int main ()
{
C mc;
C &rc = mc.foo (); // calls C &foo ()

const C &crc = mc.foo (); // so does this since mc is non-const

return 0;
}

Share this post


Link to post
Share on other sites

  • 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!