自动类型转换会引入比所希望的更多的潜在行为
//: C12:CopyingVsInitialization2.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
class Fi {};
class Fee {
public:
Fee(int) {}
Fee(const Fi&) {}
};
class Fo {
int i;
public:
Fo(int x = 0) : i(x) {}
operator Fee() const { return Fee(i); }
};
int main() {
Fo fo;
Fee fee = fo;
} ///:~
这里没有从Fo对象创建Fee fee的构造函数。Fo有一个到Fee的自动类型转换
自动类型转换运算符被调用并创建一个拷贝函数
自动类型转换应小心使用。同所有重载的运算符相比,自动类型转换在减少
代码方面非常出色,但不值得无缘无故地使用