#include <iostream>
int main(){
Value<int> x(50), y(40);
std::cout << x + y;
}
GCC will output this error:
In function `int main()':
..\main.cpp:15: error: no match for 'operator<<' in 'std::cout << operator+(const Value<_type>&, const Value<_type>&) [with _type = int](((const Value<int>&)((const Value<int>*)(&y))))'
Usually << has lower precedence than +. But i thought maybe in this case it doesn't, so I had already tried std::cout << (x + y);. Unfortunately, it didn't work. And neither did moving the friend functions outside, OR removing the friend statement.
I found the problem. It was on this line: friend std::ostream& operator<<(std::ostream& os, Value<_type>& _Value){ return os << _Value._value;}.
I changed it to: friend std::ostream& operator<<(std::ostream& os, const Value<_type>& _Value){ return os << _Value._value;}
and it worked. Probably a safety system to assure that you pass a valid reference.
operator+ returns an (unnamed) instance in your case, ie a temporary, and temporaries cannot be bound to non-const references. Hence the compile error.