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).
#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.
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.
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?