提升错误:"运算符=="的重载不明确
boost error: ambiguous overload for ‘operator==’
有人在boost中看到过这个错误吗?
我正在 CentOS 7 上使用 GCC 1.62 使用 boost 7.1 编译我的项目,我在下面遇到编译错误
是加速错误还是其他什么?
谢谢
boost/boost-1.62.0/include/boost/random/detail/polynomial.hpp: In member function ‘void boost::random::detail::polynomial::normalize()’:
boost/boost-1.62.0/include/boost/random/detail/polynomial.hpp:352:45: error: ambiguous overload for ‘operator==’ (operand types are ‘boost::random::detail::polynomial::reference’ and ‘int’)
while(size() && (*this)[size() - 1] == 0)
~~~~~~~~~~~~~~~~~~~~^~~~
boost/boost-1.62.0/include/boost/random/detail/polynomial.hpp:352:45: note: candidate: operator==(int, int) <built-in>
xxx.h:393:17: note: candidate: bool operator==(const bool&, const CPolyVal&)
STR_INLINE bool operator==(const TYPE& val, const CPolyVal& cpv)
^
xxx.h:400:1: note: in expansion of macro ‘IMPLEMENT_RHS_COMPARE_TO’
IMPLEMENT_RHS_COMPARE_TO(bool)
^~~~~~~~~~~~~~~~~~~~~~~~
xxx.h:393:17: note: candidate: bool operator==(const char&, const CPolyVal&)
STR_INLINE bool operator==(const TYPE& val, const CPolyVal& cpv)
^
xxx.h:401:1: note: in expansion of macro ‘IMPLEMENT_RHS_COMPARE_TO’
IMPLEMENT_RHS_COMPARE_TO(char)
^~~~~~~~~~~~~~~~~~~~~~~~
更多像这样。
更新了错误日志。
在我们的代码库中的某个地方。
#define IMPLEMENT_RHS_COMPARE_TO(TYPE)
STR_INLINE bool operator==(const TYPE& val, const CPolyVal& cpv)
{
TYPE cpv_equiv_val;
return cpv.ConvertTo(cpv_equiv_val) == val;
}
// end macro
IMPLEMENT_RHS_COMPARE_TO(bool)
IMPLEMENT_RHS_COMPARE_TO(char)
IMPLEMENT_RHS_COMPARE_TO(Int8)
IMPLEMENT_RHS_COMPARE_TO(Int16)
IMPLEMENT_RHS_COMPARE_TO(Int32)
IMPLEMENT_RHS_COMPARE_TO(Int64)
IMPLEMENT_RHS_COMPARE_TO(UInt8)
IMPLEMENT_RHS_COMPARE_TO(UInt16)
IMPLEMENT_RHS_COMPARE_TO(UInt32)
IMPLEMENT_RHS_COMPARE_TO(UInt64)
IMPLEMENT_RHS_COMPARE_TO(Float32)
IMPLEMENT_RHS_COMPARE_TO(Float64)
IMPLEMENT_RHS_COMPARE_TO(std::string)
从您在评论中发布的内容来看,您以某种方式设法声明了一些侵入性和过于宽泛的重载==
运算符(模板?在这种情况下,Boosts 希望左侧的boost::random::detail::polynomial::reference
被用户定义的转换运算符隐式转换为bool
,而右侧的0
应解释为false
。因此,目的是使用内置的int
与int
比较以比较两个bool
值。
此时,您的运算符==
声明显然对 Boost 代码可见,并产生歧义。 例如,发生了这样的事情
// Very loose and broad template comparison operator gets declared above
// It can compare anything to `bool`
template <typename T> bool operator ==(T lhs, bool rhs)
{
return false;
}
// Unsuspecting code begins here
// It assumes that `S` vs. `int` comparisons will be interpreted as
// built-in `bool` vs. `bool` comparisons
struct S
{
operator bool() const { return false; }
void normalize()
{
S s;
s == 0; // Error: ambiguous comparison
}
};
相关文章:
- 继承函数的重载解析
- 你能重载对象变量名本身返回的内容吗
- 从父命名空间重载类型
- 使用C++中的模板和运算符重载执行矩阵运算
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 重载操作程序时出错>>用于类中的字符串 memebr
- 一个关于在C++中重载布尔运算符的问题
- 不同翻译单元中不可重载的非内联函数定义
- 为什么使用SFINAE而不是函数重载
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- 将重载的成员函数传递给函数模板
- c++:可变模板和函数重载
- 重载元组索引运算符-C++
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 重载==不适用于二进制树
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 重载运算符new[]的行为取决于析构函数
- 正在尝试重载二进制搜索树分配运算符
- 重载Singly Linked List中的赋值运算符
- 取消引用运算符不能重载