R
Roger Leigh
This code works (GCC 3.3.3):
#include <iostream>
int main()
{
bool a = true;
std::cout << "True and false\n"
<< (a == true) ? 't' : 'f';
std::cout << "\n";
return 0;
}
But this code does not:
#include <iostream>
int main()
{
bool a = true;
std::cout << "True and false\n"
<< (a == true) ? 't' : 'f'
<< "\n";
return 0;
}
test.cc: In function `int main()':
test.cc:9: error: invalid operands of types `char' and `const char[2]' to
binary `operator<<'
However, if I enclose the entire ternary expression in parentheses
"((a == true) ? 't' : 'f')" then it does compile.
What is different between these two forms? Both return a char, but
only the latter returns a std:stream& when used in the above
expression.
Many thanks,
Roger
#include <iostream>
int main()
{
bool a = true;
std::cout << "True and false\n"
<< (a == true) ? 't' : 'f';
std::cout << "\n";
return 0;
}
But this code does not:
#include <iostream>
int main()
{
bool a = true;
std::cout << "True and false\n"
<< (a == true) ? 't' : 'f'
<< "\n";
return 0;
}
test.cc: In function `int main()':
test.cc:9: error: invalid operands of types `char' and `const char[2]' to
binary `operator<<'
However, if I enclose the entire ternary expression in parentheses
"((a == true) ? 't' : 'f')" then it does compile.
What is different between these two forms? Both return a char, but
only the latter returns a std:stream& when used in the above
expression.
Many thanks,
Roger