vla*_*378 4 c++ class switch-statement implicit-conversion
因为如果我定义operator==
然后比较将是可能的:
class My
{
int x;
// ...
public:
My(int);
bool operator==(const My & y);
// ...
};
//...
My one = 1;
switch (one)
{
case 1 : // anything
default : // ...
}
Run Code Online (Sandbox Code Playgroud)
但它仅适用于整数类型。为什么?