【发布时间】:2012-01-04 13:52:03
【问题描述】:
当涉及到构造函数时,添加关键字explicit 可以防止热心的编译器在不是程序员的初衷时创建对象。这种机制也适用于铸造运营商吗?
struct Foo
{
operator std::string() const;
};
例如,在这里,我希望能够将 Foo 转换为 std::string,但我不希望这种转换隐式发生。
【问题讨论】:
标签: c++ casting operator-keyword explicit