Note upfront: The problem relates to a vector-class implemented by myself, and has nothing to do with std::vector
Consider the following operator-overloading:
//in the Vector-class(declaration)
friend Vector operator+(const Vector& a, const Vector& b);
//outside the Vector-class(implementation)
Vector operator+(const Vector& a, const Vector&b) {
//...
}
It takes references to two vectors, and returns their sum. Now when i try something like the following:
Vector foo();
Vector bar();
Vector byVal = foo + bar; //using objects
Vector byRef = &foo + &bar; //using address
in both cases my IDE tells me the following:
expression must have integral or unscoped enum-type
In the second case this makes sense, because i would only pass a yielded pointer when the called function would take a pointer, and for a function that takes a reference, i can pass the object itself, but i don't understand why just using the object is not possible here.
What makes it more confusing for me, is that the following seems to be possible:
Vector* foo = new Vector();
Vector* bar = new Vector();
Vector foobar = *foo + *bar;
That is i can use de-referenced pointers with the overloaded operator.
What is the cause of this behaviour, and how am i supposed to use my overloaded operator in this case?