- C/C++ code
#include <iostream> using namespace std; bool isright() { return true; } void main() { cout << isright()?"good":"bad"<<"results"<<endl; }
提示错误
error C2296: '<<' : illegal, left operand has type 'char [4]'
error C2297: '<<' : illegal, right operand has type 'char [8]'
解释一下,不胜感激!!!
------解决方案--------------------
cout << isright()?"good":"bad"<<"results"<<endl;
输出操作符<<的优先级高条件操作符的优先级,会先计算cout << isright(),然后返回一个cout,再计算后面的cout?"good",这就发生了编译错误,修改为:
cout << (isright()?"good":"bad")<<"results"<<endl;