overloading operators for vector addition
Hello everyone,
I'm trying to overload some operators for the vector class but my attempts don't seem to do anything. They compile fine, they just won't add/subtract/multiply...
Here's a sample for the + operator.
Code:
template <class T1, class T2>
vector<T1> &operator+(vector<T1>& v1, vector<T2>& v2)
{
for(UINT i = 0; i < v1.size(); i++)
v1[i] += v2[i];
return v1;
}
The when I call it, it's like this
Code:
vector<int> v1, v2;
v1.assign(4, 4);
v2.assign(4, 6);
v1 = v1 + v2;
Then when I look in v1, the values are still {4, 4, 4, 4}.
So, how do you do it?