Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
description:
The 2nd and 3rd operands to the conditional operator must be of the same type. If one of the two can be converted to the other, the conversion will occur. Note: if a conversion exists for each of the operands into the other's type, the program is ill-formed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
struct Foo
{
int x;
operator int()
{
return 21;
}
};
int main(int argc, char** argv)
{
Foo f;
f.x = 11;
std::cout << (0?3:f) << std::endl;
return 0;
}
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content