我有问题。为什么我不能编译这个?怎么了?
#include <boost/iterator/indirect_iterator.hpp>
bool finder(std::list<SomeObject*>::const_iterator first,
std::list<SomeObject*>::const_iterator last,
const SomeObject& x)
{
return std::find(boost::make_indirect_iterator(first),
boost::make_indirect_iterator(last),
x) != boost::make_indirect_iterator(last);
}
//此代码来自我之前发布的帖子
我有错误:
C:\ Program Files(x86)\ Microsoft Visual Studio 8 \ VC \ include \ algorithm(40):错误C2784:'bool std :: operator ==(const _Ty&amp;,const std :: complex&lt; _Other&gt; &amp;)':无法推断'const std :: complex&lt; _Other&gt;的模板参数&安培;”来自'const SomeObject
C:\ Program Files(x86)\ Microsoft Visual Studio 8 \ VC \ include \ algorithm(40):错误C2784:'bool std :: operator ==(const 的std ::复杂&LT; _其他&GT; &amp;,const _Ty&amp;)':无法推断出模板 'const std :: complex&lt; _Other&gt;的参数&安培;”来自'SomeObject'
C:\ Program Files(x86)\ Microsoft Visual Studio 8 \ VC \ include \ algorithm(40):错误C2784:'bool std :: operator ==(const 的std ::对&LT; _Ty1,_Ty2&GT; &amp;,const std :: pair&lt; _Ty1,_Ty2&gt; &amp;)':不能 推导出'const std :: pair&lt; _Ty1,_Ty2&gt;的模板参数&安培;”从 SomeObject
和几个类似的错误..
我定义了operator==
:
bool operator==(const SomeObject& x, const SomeObject& y)
{
return x.id1() == y.id1();
}
我使用VS 2005。
如何解决?怎么了?也许这是VS2005的bug?你能编译吗?
答案 0 :(得分:1)
这意味着* advance(boost :: make_indirect_iterator(first),some_int)无法传递给operator ==,它接受const SomeObject&amp;。这很奇怪。
一个建议是将bool operator == in namespace std。
namespace std {
bool operator==(const SomeObject& x, const SomeObject& y)
{
return x.id1() == y.id1();
}
}