将逻辑 OR 与 cout 运算符一起使用
Using logical OR with cout operator
为什么bitor
在与运算符一起使用时不起作用cout
这行得通
int a=5,b = 6,d = a bitor b;
cout << d << endl;
这是抛出错误
int a=5,b=6;
cout << a bitor b << endl;
错误信息:
invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'
cout << a bitor b << endl;
根据运算符优先级,operator<<
的优先级高于operator bitor
。然后cout << a bitor b << endl;
将被解释为
(cout << a) bitor (b << endl);
而b << endl
无效。
您可以添加括号以指定正确的优先级,例如
cout << (a bitor b ) << endl;
相关文章:
- 为什么常量词在重载运算符中不与 ostream 对象一起使用<<?
- 将 [][] 运算符与向量一起使用?
- 不能将重载比较运算符与 Catch 测试一起使用
- 让类与运算符一起工作更简单的方法
- #define 与运算符一起使用
- 是否可以将引用类型别名与指针运算符一起使用来声明对指针的引用?
- 返回对象如何与分配运算符一起工作
- 将逻辑 OR 与 cout 运算符一起使用
- 为什么在 sizeof() 函数中与 * 运算符一起使用和不使用 * 运算符时,指向结构变量的指针大小会有所不同?
- 我可以将 std:fixed 或 std::setprecision() 与>>运算符一起使用吗?
- 如何使 QList<Type*> 与 indexOf() 和自定义运算符==()一起使用?
- 将 std::forward 与 typeid 运算符一起使用是否有意义
- 如何将 std::<list>::reverse_iterator 与运算符 + 一起使用?
- 与类型转换运算符一起使用时条件运算符"?:"的编译器错误
- 如何将运算符[]与运算符=一起使用
- 与条件运算符一起使用时,动作不一致
- 我可以将enable_if之类的东西与隐式转换运算符一起使用吗
- 如何将运算符+和运算符=一起使用
- C++如何验证输入以与重载>>运算符一起使用
- 如何使用 std::find 与不是 std::less 的<运算符一起使用