A member operator +()
have only one parameter, the right operand. The left or first is always *this
. Depending of your situation, you need just a base +
, a virtual +
or a template. A free operator +()
take two argumets, "left" and "right".
In your code:
template< typename T >
class Operations{
public:
friend T operator+( const T& sp, const T& nsp ){
return T(sp.dimension + nsp.dimension);
};
};
You whant a member or a friend?
If a friend, the problems is that +() have to be define outside the class, it is only a friend, not a member.
template< typename T >
T operator+( const T& sp, const T& nsp );
template< typename T >
class Operations{
public:
friend T operator+<T>( const T& sp, const T& nsp );
};
template< typename T >
T operator+( const T& sp, const T& nsp )
{
return T(sp.dimension + nsp.dimension);
}
BUT !!!! Now you have the REAL problem: +() uses a privat member of the derived class, not the base class, so it need to be a friend of the derived class. I think you need to rethink ;-) your design. If you are so confortable using dimension in Operations.. could it be a protected member of Operations??? All your Operations have an dimension?