I have two integers and trying to pass them to cout.
int a =1;
int b= 3;
cout<<a&b;
Compiler tells:
Error 2 error C2676: binary '&' : 'std::basic_ostream<_Elem,_Traits>' does not define this operator or a conversion to a type acceptable to the predefined operator
But a&b returns int that is understandable for ‘<<‘ operator.
Why this error rises?
Due to operators precedence, you need to use parenthesis:
The
<<operator binds more tightly than&, so omitting the parenthesis makes thecompiler undertand it as
(cout << a) & b, which explains the error report: The & operator can’t be used with a stream (the returned object fromcout << a)and an int.