QList 的==问题

龙内cool 2013-10-16 05:52:29
 QList<QextPortInfo> newPortInfo;
QList<QextPortInfo> currPortInfo;
if(newPortInfo==currPortInfo){}
在执行上述代码时,出现了


请问各位大神怎么破?
...全文
421 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Chirive 2013-10-18
  • 打赏
  • 举报
回复
bool QextPortInfo::operator==(const QextPortInfo &other) { //在这里陈述下newPortInfo和currPortInfo为什么相等 }
龙内cool 2013-10-17
  • 打赏
  • 举报
回复
引用 3 楼 ao834391367 的回复:
楼上说的都对 要重载==操作符
请问下这个操作符,能不能帮忙写下?实在是不知道怎么搞了。
龙内cool 2013-10-17
  • 打赏
  • 举报
回复
引用 2 楼 Inhibitory 的回复:
bool QList::operator==(const QList<T> & other) const Returns true if other is equal to this list; otherwise returns false. Two lists are considered equal if they contain the same values in the same order. This function requires the value type to have an implementation of operator==().
template <typename T>
Q_OUTOFLINE_TEMPLATE bool QList<T>::operator==(const QList<T> &l) const
{
    if (p.size() != l.p.size())
        return false;
    if (d == l.d)
        return true;
    Node *i = reinterpret_cast<Node *>(p.end());
    Node *b = reinterpret_cast<Node *>(p.begin());
    Node *li = reinterpret_cast<Node *>(l.p.end());
    while (i != b) {
        --i; --li;
        if (!(i->t() == li->t()))
            return false;
    }
    return true;
}
这是QList.h里面的==的定义,请问只有一个参数怎么来进行比较?
  • 打赏
  • 举报
回复
楼上说的都对 要重载==操作符
Inhibitory 2013-10-16
  • 打赏
  • 举报
回复
bool QList::operator==(const QList<T> & other) const Returns true if other is equal to this list; otherwise returns false. Two lists are considered equal if they contain the same values in the same order. This function requires the value type to have an implementation of operator==().
  • 打赏
  • 举报
回复
你的QextPortInfo实现了==操作符的重载了吗

16,816

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧