Download MetaTrader 5
To add comments, please log in or register
Do you need private account monitoring? The Signals will provide you one!
flourishing
395
flourishing 2012.09.06 10:36 

here is my test code.

//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
#include <Arrays\ArrayObj.mqh>

int RandInt(int x,int y)
{
   return rand()%(y-x+1)+x;
}

class Person:CObject
{
   public:
   int money;
   string name;
   Person(){money = RandInt(1,100);}   
};


int OnInit()
  {
//--- 
      MathSrand(GetTickCount());
   CArrayObj* persons = new CArrayObj();
   for(int i =0;i<10;i++)
      persons.Add(new Person());
   
   
   persons.Sort();
   /// here how to make the Sort function work??
   /*
   Note

   Sorting an array is always ascending.
   For arrays of primitive data types (CArrayChar, CArrayShort, etc.), 
   the parameter mode is not used.
   For the array CArrayObj, 
   multivariate sort should be implemented in the method Sort (int) derived class.

   the documentation said like that. but i don't how to.
   
   */
   
   for(int i=0;i<10;i++)
     {
      Person* tp = persons.At(i);
      Print(tp.money);
     }
   
  
   
   delete(persons);
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   
  }
//+------------------------------------------------------------------+
the question is in the code comments .please see  the comments under  persons.sort() 
/
To add comments, please log in or register