How can I make this operator overload work?

44 views Asked by At

I am using C++, I am relatively new to the language. Before even compiling, VSCode highlights that my transform call is overloaded. I suspect that this is because of the unclear typename, but this is needed to overload a vector, so how can I fix this?

template <typename U>
vector<U> operator+(const vector<U>& v1, const vector<U>& v2) {
    vector<U> result(v1.size());
    transform(v1.begin(), v1.end(), v2.begin(), result.begin(), [] (U& a, U& b) {return a + b; });
    return result;
}

I have tried changing from U to T, or using vector double throughout, but nothing fixed the issue.

0

There are 0 answers