• 5257阅读
  • 2回复

[提问]重载‘<’出现的问题 [复制链接]

上一主题 下一主题
离线83888788
 
只看楼主 倒序阅读 楼主  发表于: 2011-03-30
因为要使用qSort()
所以重载了'<'


  1. class BeginEndPosition
  2. {
  3. public:
  4.     BeginEndPosition()
  5.     {
  6.         beginPos=0;
  7.         endPos=0;
  8.     }
  9.     BeginEndPosition(quint64 b,quint64 e)
  10.     {
  11.         beginPos=b;
  12.         endPos=e;
  13.     }
  14.     quint64 beginPos;
  15.     quint64 endPos;
  16.     bool operator <(BeginEndPosition const&r)const ;
  17. };
  18. bool BeginEndPosition::operator <(BeginEndPosition const&r) const
  19. {
  20.     return this->endPos<r.endPos;
  21. }


编译输出如下:


如果我不重载,他又说我没有定义,很无奈啊。。。
谢谢大家!

这是是 first define的位置
在q.global.h中

  1. inline void qt_noop() {}
  2. /* These wrap try/catch so we can switch off exceptions later.
  3.    Beware - do not use more than one QT_CATCH per QT_TRY, and do not use
  4.    the exception instance in the catch block.
  5.    If you can't live with those constraints, don't use these macros.
  6.    Use the QT_NO_EXCEPTIONS macro to protect your code instead.
  7. */

[ 此帖被83888788在2011-03-30 23:04重新编辑 ]
离线wxj120bw

只看该作者 1楼 发表于: 2011-03-31
引用楼主83888788于2011-03-30 22:03发表的 重载‘<’出现的问题 :
因为要使用qSort()
所以重载了'<'
[code]
.......

楼主的operator函数的实现是不是放在头文件实现的,如果放在头文件,那就把她放在cpp文件里,我尝试了下,如果放在h文件里,就提示多次定义的错误
离线83888788
只看该作者 2楼 发表于: 2011-03-31
回 1楼(wxj120bw) 的帖子
这样说吧,你说的就在点上
快速回复
限100 字节
 
上一个 下一个