## Recommended Posts

Porco_Rosso    122
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 on other sites
Sharlin    864
ts16Vector2::operator ts8Vector2() const

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

##### Share on other sites
Porco_Rosso    122
Thanks,

that was the problem!

##### 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?