Error: Invalid operands for Binary expression

I've created a class that works with vectors doing various calculations and what not. I have overloaded operators that I've created outside of the main in separate header and class files. Ive tested them and the overloaded operators work correctly when I paste them into a the main file but when I have them defined in the other class files and I try to access them in the main class I get an error saying invalid operands to a binary expression. I also have other classes with overloaded operators that work just fine in the main class so I'm not sure what I did wrong here?

This is how I have my header set up, the definitions to these are in a separate class file which I don't think I need to include considering I have them tested and working so I don't think that's the problem (correct me if I'm wrong).
1
2
3
4
5
6
7
8
9
class VectorClass{
    friend vector<float> operator+( const vector<float>&, const vector<float>& );
    friend vector<float> operator...
    friend vector<float> operator...
private:
    ...
    ...
public:
    ...


And then in my main class looks vaguely like this
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Name of vector class"
int main(){
vector<float> vR, v1, v2;

v1.push_back('some value');
...
v2.push_back('some value');
...

vR = v1 + v2;  //  Invalid operands here

return 0;
}


And like I said, I have other classes with overloaded operators set up the same way which work fine being implemented the way I have these, so I'm not sure where the problem is at.
1
2
class VectorClass{
    friend vector<float> operator+( const vector<float>&, const vector<float>& );
¿what does `VectorClass' have to do with anything?

I am not sure about the rules of when a friend specification includes the function declaration. In this case it seems that you do need to declare the function.
1
2
3
4
vector<float> operator+(const vector<float>&, const vector<float>&);

class VectorClass{
   friend vector<float> operator+(const vector<float>&, const vector<float>&);



By the way http://www.cplusplus.com/reference/valarray/valarray/operators/
The VectorClass has to deal with program functions that aren't specific to this problem so I left its functions out.Aand that got it working, I'm not sure why I had to declare those and not others but oh well, I look into it lol. Thanks for the help!
What I mean is why do you need operator+ that works with std::vector<float> to be a friend of `VectorClass', ¿do you really need to execute private member functions or access the state of a global/default constructed object?
Topic archived. No new replies allowed.