简体   繁体   中英

Using logical OR with cout operator

Why bitor doesn't work while using it with cout operator

This works

int a=5,b = 6,d = a bitor b;
cout << d << endl;

This is throwing error

int a=5,b=6;
cout << a bitor b << endl;

error message:

invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'
  cout << a bitor b << endl;

According to the Operator Precedence , operator<< has higher precedence than operator bitor . Then cout << a bitor b << endl; will be interpreted as

(cout << a) bitor (b << endl);

while b << endl is invalid.

You can add parentheses to specify the correct precedence, eg

cout << (a bitor b ) << endl;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM