Jump to content
  • Advertisement
Sign in to follow this  
Porco_Rosso

C++ Operator overloading

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

Hello - I was wondering if anybody had the answer to this problem - I am making a few vector classes in C++ - and i have been happily overlaoding all of their operators - however when casting between vector types i have a problem if the vector i am casting is const ... e.g pointPosition = (ts16Vector2)*pDrawing->GetPoint(point); where GetPoint returns a vector of type ts8Vector* - the problem is that my casting func - e.g. ts16Vector2::operator ts8Vector2() { ts8Vector2 returnVec; returnVec.x = (s8)x; returnVec.y = (s8)y; return returnVec; }; uses implicit "this" which I guess is not const - anyway the compiler complains saying its invalid and if the vector I want to cast is not const it works fine..?! anybody know? thanks, Ross

Share this post


Link to post
Share on other sites
Advertisement
ts16Vector2::operator ts8Vector2() const

This will pass the this pointer as a constant. You should liberally mark all non-mutating memberfunctions as such.

Share this post


Link to post
Share on other sites
Random question: Why is GetPoint() returning a pointer? Can it ever return NULL? If so, shouldn't you be checking for NULL? If not, shouldn't you at least return by reference, or (better yet) return by value?

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!