Sign in to follow this  

C++ Operator overloading

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

This topic is 4055 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this