📄 operatorconversion.cpp
字号:
class The_Other_One {
int i;
public:
The_Other_One(int ii = 0) : i(ii) {}
};
class The_One {
int x;
public:
The_One(int xx) : x(xx) //把int类型转换成The_One类型
{}
operator The_Other_One() const// 把The_One类型转换成The_Other_One类型,且自动执行
{
return The_Other_One(x); //返回一个The_Other_One对象
}
};
void g(The_Other_One) {}
void main() {
The_One a(1);
g(a);
// g(1); // Calls g( The_Other_One(1) )
} ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -