operator== 和 boost::detail::atomic_count 中的显式构造函数?

Posted

技术标签:

【中文标题】operator== 和 boost::detail::atomic_count 中的显式构造函数?【英文标题】:operator== and explicit constructor in boost::detail::atomic_count? 【发布时间】:2014-04-05 12:47:33 【问题描述】:

我发现 boost::detail::atomic_count 没有 operator==() 的声明和定义。

如果我有以下情况: boost::detail::atomic_count i(0); if (i == 0) // do something

问题

    由于 boost::detail::atomic_count 有显式构造函数,所以 if 语句中的 0 似乎不会用作构造函数的参数? 没有定义和声明 operator==;编译器如何将 i 与零进行比较?

提前致谢。

附:该代码使用 gcc 4.6.2 和 boost 1.47 编译并运行良好。在 Linux 上。

【问题讨论】:

【参考方案1】:

查看the sourcecode 发现boost::detail::atomic_count 隐式转换为long,用于相等比较。

【讨论】:

啊,有趣。谢谢!

以上是关于operator== 和 boost::detail::atomic_count 中的显式构造函数?的主要内容,如果未能解决你的问题,请参考以下文章