Following code is in simplest form:
struct X {
operator char () const { return \'a\'; }
};
int main ()
{
X obj, *p = &obj;
char a = *p; // ok
char
The error is correct. operands to ?:
have different types: ‘X’ the first, and ‘char’ the second. The compiler cannot know that you want the expression to be a char in the end - that will happen later, after the evaluation of the whole expression (true)? *p : 'z';
- an evaluation which cannot be done in the first place due to type discrepancies.