I am trying to create an operator overloading function to add 2 vectors. Declaration goes like this:
class VecOperations
{
public:
std::vector<double> operator + (const std::vector<double> &, const std::vector<double> &);
};
But there is error binary operator + has too many parameters
. Any idea why this is so? I want to add 2 vectors with operator overloading.
Edit: After taking a look at https://stackoverflow.com/a/4421719/9329547
class X { X& operator+=(const X& rhs) { // actual addition of rhs to *this return *this; } }; inline X operator+(X lhs, const X& rhs) { lhs += rhs; return lhs; }
I am confused as in my question I am not passing class instance to the operator overloaded function, but passing 2 vectors. Can someone explain what is proper way to declare the function?