I'm having trouble overriding the + and - operators.
My struct definition with overloaded methods:
Code:struct vectorf { float x; float y; float z; const vectorf operator+(const vectorf other); const vectorf operator-(const vectorf other); }; const vectorf vectorf::operator+(vectorf other) { vectorf ans; ans.x = x + other.x; ans.y = y + other.y; ans.z = z + other.z; return ans; } const vectorf vectorf::operator-(const vectorf other) { vectorf ans; ans.x = x - other.x; ans.y = y - other.y; ans.z = z - other.z; return ans; }
And this is the line of code giving me trouble:
Code:glTranslateVector(MAIN_POSITION - BACKGROUND_POSITION);
The error says:
" error C2678: binary '-' : no operator found which takes a left-hand operand of type 'const vectorf' (or there is no acceptable conversion) "
And:
" could be 'const vectorf vectorf:: operator -(const vectorf)' "
Any help would be greatly appreciated.
-Salbris




Reply With Quote