c++11 - 将 shared_ptr 隐式转换为 bool
问题描述
我想知道为什么 shared_ptr 的 bool 转换运算符在 an 中可以正常工作if-statement
,但在到 (bool) 返回值的隐式转换中却不行。
std::shared_ptr<const OfflineContainer> m_pContainer;
bool MyClass::IsInitialized() const
{
if (m_pContainer) // compi;es
return true;
return m_pContainer; // won't compile
}
编译器消息:
Error C2440 'return': cannot convert from 'const std::shared_ptr<const MyClass>' to 'bool'
解决方案
推荐阅读
- kubernetes - 使用 Helm 安装后 Prometheus 服务器处于挂起状态
- python - 如何将函数导入其他文件?
- visual-studio - 更新每个循环容器中的查询
- azure-powershell - 天蓝色应用程序网关警报自动化
- python - 使用 rstrip("\n") 从 readlines 中删除 \n
- r - 从 r 中的数据集创建后进先出表
- cron - AirFlow 是否支持自定义日历或 Flexi 日历?
- javascript - 返回猫鼬查询结果
- apache-flink - 用 pulsar 和 flink 端到端交付恰好一次
- r - 未找到用于 Bioconductor 包 RBGL 的 R 包 BH