比较deques时的问题 [英] Problem when comparing deques

查看:51
本文介绍了比较deques时的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试编写两个自制结构的deques时遇到了一些困难。

这是我的结构和双端声明:

I''m having some difficulties when trying to comapare two deques of a selfmade struct.
This is my struct and the deque declaration:

class iterator
{
public:
struct PosPtrs
{
    NodeLevel Level;
    TreeElement Element;
    bool operator ==(const PosPtrs& input)
    {
        return Level == input.Level && Element == input.Element;
    }
    bool operator== (PosPtrs& input)
    {
        return Level == input.Level && Element == input.Element;
    }
};
std::deque<PosPtrs> TreeHistory;
private:
....
};





当尝试



When Trying

iterator it1;
iterator it2;
return it1.TreeHistory == it2.TreeHistory;



我收到编译器错误C2678:



d:\program files\microsoft visual studio 10.0 \vc\include\xutility(2990):error C2678:binary''= ='':没有找到哪个运算符带有''const BaseTree :: iterator :: PosPtrs''类型的左手操作数(或者没有可接受的转换)

1> d:\program files\microsoft sdks\windows\v7.0a\include\guiddef.h(192):可能是''int operator ==(const GUID&,const GUID&)' '[使用参数依赖查找找到]

1> d:\program files\microsoft visual studio 10.0 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;)''

1> d:\ program files \ microsoft visual studio 10.0 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ '

1> d:\program files\microsoft visual studio 10.0 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ '

1> d:\program files\microsoft visual studio 10.0 \vc\include\system_error(408):或''bool std :: operator ==(const std :: error_code&,const std :: error_condition& ;)''

1> d:\program files\microsoft visual studio 10.0 \vc\include\system_error(416):或''bool std :: operator ==(const std :: error_condition&,const std :: error_code& ;)''

1> d:\users\maxime \documents\visual studio 2010\projects\regfilehook\regfilehook\xmlfilereadwrite.h(156):或''bool BaseTree :: iterator :: PosPtrs :: operator == (const BaseTree :: iterator :: PosPtrs&)''

1> d:\users\maxime \documents\visual studio 2010 \projects\regfilehook \regfilehook \ xmlfilereadwrite.h(160):或''bool BaseTree :: iterator :: PosPtrs :: operator == (BaseTree :: iterator :: PosPtrs&)''

1>尝试匹配参数列表''(const BaseTree :: iterator :: PosPtrs,const BaseTree :: iterator :: PosPtrs)''

1> ....




最后几行令我困惑。编译器尝试将运算符++()函数的参数列表与2个参数进行匹配?我找了一个运算符==总是定义只有一个参数(尝试这也没有帮助,它在编译器错误中结束就像预期的那样)..



先谢谢


I get a compiler error C2678:

d:\program files\microsoft visual studio 10.0\vc\include\xutility(2990):error C2678: binary ''=='' : no operator found which takes a left-hand operand of type ''const BaseTree::iterator::PosPtrs'' (or there is no acceptable conversion)
1> d:\program files\microsoft sdks\windows\v7.0a\include\guiddef.h(192): could be ''int operator ==(const GUID &,const GUID &)'' [found using argument-dependent lookup]
1> d:\program files\microsoft visual studio 10.0\vc\include\exception(470): or ''bool std::operator ==(const std::_Exception_ptr &,const std::_Exception_ptr &)''
1> d:\program files\microsoft visual studio 10.0\vc\include\exception(475): or ''bool std::operator ==(std::_Null_type,const std::_Exception_ptr &)''
1> d:\program files\microsoft visual studio 10.0\vc\include\exception(481): or ''bool std::operator ==(const std::_Exception_ptr &,std::_Null_type)''
1> d:\program files\microsoft visual studio 10.0\vc\include\system_error(408): or ''bool std::operator ==(const std::error_code &,const std::error_condition &)''
1> d:\program files\microsoft visual studio 10.0\vc\include\system_error(416): or ''bool std::operator ==(const std::error_condition &,const std::error_code &)''
1> d:\users\maxime\documents\visual studio 2010\projects\regfilehook\regfilehook\xmlfilereadwrite.h(156): or ''bool BaseTree::iterator::PosPtrs::operator ==(const BaseTree::iterator::PosPtrs &)''
1> d:\users\maxime\documents\visual studio 2010\projects\regfilehook\regfilehook\xmlfilereadwrite.h(160): or ''bool BaseTree::iterator::PosPtrs::operator ==(BaseTree::iterator::PosPtrs &)''
1> while trying to match the argument list ''(const BaseTree::iterator::PosPtrs, const BaseTree::iterator::PosPtrs)''
1> ....


The last lines are confusing me. The compiler tries to match an argument list of a operator++() function with 2 arguments? I tought an operator== was always defined with only one argument (trying this doesn''t helps either, it ends like expected in a compiler error)..

Thanks in Advance

推荐答案

class iterator
{
public:
struct PosPtrs
{
    NodeLevel Level;
    TreeElement Element;
    bool operator ==(const PosPtrs& input) const
    {
        return Level == input.Level && Element == input.Element;
    }
};
std::deque<posptrs> TreeHistory;
private:
....
};





线索来自这条消息:

d:\program files\microsoft visual studio 10.0 \vc\include\xutility(2990):错误C2678:二进制''=='':没有找到哪个运算符带有''const BaseTree :: iterator :: PosPtrs''类型的左手操作数(或者没有可接受的转换)



你的左手操作数也需要是const。



The clue comes from this message:
d:\program files\microsoft visual studio 10.0\vc\include\xutility(2990):error C2678: binary ''=='' : no operator found which takes a left-hand operand of type ''const BaseTree::iterator::PosPtrs'' (or there is no acceptable conversion)

Your left hand operand needs to be const also.


这篇关于比较deques时的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆