【发布时间】:2019-04-05 16:15:29
【问题描述】:
我有一个类型定义的 shared_ptr,我在条件检查中使用它。
它是这样定义的:
typedef std::shared_ptr<T> typeTPtr;
然后我将它传递给一个采用 bool 参数的函数:
void Foo(bool);
当我尝试这样做时:
typeTPtr ptrT = ...
Foo(ptrT);
我得到一个错误提示
无法将参数从 T 转换为 bool
我相信 std::shared_ptr 明确定义了 bool 运算符。 为什么编译器不将 shared_ptr 转换为 bool? 我正在使用 Visual C++ 2017
谢谢。
【问题讨论】:
-
我猜这两个答案都是正确的,所以应该接受其中一个!
标签: c++ visual-c++ shared-ptr