I am writing a class that has a std::vector
as member, and I'd like to be able to modify its data in bulk by using default operators +
/+=
, *
/*=
, etc taking a scalar as argument, e.g.
MyClass<float> obj;
obj += 4.0;
I'm tring to define the operator overload as:
template <class _type>
matrix2D<_type>& matrix2D<_type>::operator=(matrix2D<_type> _mat){
std::swap(_mat,*this);
return *this;
};
template <class _type>
template <typename _input_type>
myClass<_type> myClass<_type>::operator*(_input_type _val) {
for (int i = 0; i < data.size(); ++i) data[i] *= _val;
return *this;
};
template <class _type>
template <typename _input_type>
myClass<_type> myClass<_type>::operator*=(_input_type _val) {
for (int i = 0; i < data.size(); ++i) data[i] *= _val;
return *this;
};
I get no compile or runtime errors, but the values remain unchanged. I've tried to a multitude of different types of return values (MyClass&
, void
) and passing a myClass
object as argument. What am I missing?