who knows how to used structure member variable name as a function parameter?

 
I want to make a function that can automatically sort according to the high, low, open, and close values in the mqlrates structure, but when calling the function, I find that the member variable name cannot be directly used as a function parameter. 
void getdata::Get_struct_sort(Type_Name &array[],Object_Name name)//对结构体数据进行排序
{
   Type_Name car;
   int num = 0;
   int count = ArraySize(array);
   
   for(int i = 0; i < count; i++)
   {
      for(int k = 0; k < count - i - 1; k++)
      {
         if(array[k].name> array[k + 1].name)
         {
            car = array[k];
            array[k] = array[k + 1];
            array[k + 1] = car;
         }
      }
   }
}


Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / History Data Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / History Data Structure
  • www.mql5.com
History Data Structure - Data Structures - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Blur Darkness I find that the member variable name cannot be directly used as a function parameter. 

Correct. Pass a comparison function.

struct Less{
template <typename Datatype>
   bool     is_before(const Datatype& a, const Datatype& b) const{return a < b;}
   void     Less(void){}   // Prevent "possible use of uninitialized variable"
 private:
   char onebyte;  // Prevent "struct has no members, size assigned to 1 byte"
};
struct LessRatesHigh{
   bool     is_before(const MqlRates& a, const MqlRates& b) const{return a.high < b.high;}
   void     LessRatesHigh(void){}   // Prevent "possible use of uninitialized variable"
 private:
   char onebyte;  // Prevent "struct has no members, size assigned to 1 byte"
};
⋮
LessRatesHigh comp; data.Get_struct_sort(rates, comp);
⋮
template <typename Type_Name, typename BinaryPredicate> 
void getdata::Get_struct_sort(Type_Name &array[],const BinaryPredicate& comp)
    ⋮
    if(comp.is_before(array[k+1], array[k])           // if(array[k].name> array[k + 1].name
 
William Roeder #:

Correct. Pass a comparison function.

It's awesome!
Reason: