Compare

列表中的数据项与列表中其它元素数据进行比较。

virtual int  Compare(
   const CObject*  node,     // 将要比较的节点
   const int       mode=0    // 比较模式
   ) const

参数

node

[输入]  进行比较的列表项指针

mode=0

[输入]  比较的变形

返回值

0 - 列表项相等的情况, -1 - 如果列表项小于表中另一比较的项 (节点), 1 - 如果列表项大于表中另一比较的项 (节点)。

注释

类 CObject 中的方法 Compare () 返回 0 且不执行任何动作。如果您期望比较派生类的数据, 则方法 Compare (...) 应予以实现。模式 (mode) 参数应在实现多元比较时使用。

例如:

//--- 例程 CObject::Compare(...)
#include <Object.mqh>
//---
void OnStart()
  {
   CObject *object_first,*object_second;
   //---
   object_first=new CObject;
   if(object_first==NULL)
     {
      printf("对象创建错误");
      return;
     }
   object_second=new CObject;
   if(object_second==NULL)
     {
      printf("对象创建错误");
      delete object_first;
      return;
     }
   //--- 设置关联
   object_first.Next(object_second);
   object_second.Prev(object_first);
   //--- 比较对象
   int result=object_first.Compare(object_second);
   //--- 删除对象
   delete object_first;
   delete object_second;
  }