Quote:Original post by daniel_i_l
But the problem is that if I'm working with pointers to the IVec class, then in order to use the operators I'll have to dereference all the pointers.
Then don't work with pointers. Work with references instead (i.e. just write the values, and have your overloads accept and return references where appropriate, following the usual conventions). References were actually added to the language more or less specifically to support operator overloading. They allow you to get 'virtual' behaviour for function calls (including operator overloads), too.
However, keep in mind that C++ does not have multiple dispatch built in. In 'x + y', only the exact derived type of x will matter for looking up the implementation, unless you explicitly re-dispatch, e.g.
IVec IVec::operator+(const IVec& rhs) { return rhs.addedToBase(*this);}// Similarly for each derived type, naming a different helperIVec IVec::addedTo(const IVec& lhs) { // protected virtual; does the work // SImilarly for each derived type, accepting a parameter of that type}
But honestly, all of this is kind of moot, because operator overloads generally belong to simple mathematical types, and simple mathematical types have no reason for any polymorphic behaviour.