Download MetaTrader 5

Functions with enum parameter and functions with variable arguments

To add comments, please log in or register
Bogdan Tenea
202
Bogdan Tenea  

Hello, I'm having trouble defining functions something like these:

uint CFileCsv::WriteElement(const enum value)
  {
//--- checking
   if(m_handle<0) return(0);
//---
   if(!first) line.Append(delim);
   line.Append(EnumToString(value));
   first=false;
   return StringLen(EnumToString(value));

  }

enum keyword is not accepted. Using it breaks EnumToString function

uint CFileCsv::WriteElement(...)
  {
     // do something with var args ?

  }

JMRodMartins
238
JMRodMartins  
"GoD2.0:

Hello, I'm having trouble defining functions something like these:

uint CFileCsv::WriteElement(const enum value)
  {
//--- checking
   if(m_handle<0) return(0);
//---
   if(!first) line.Append(delim);
   line.Append(EnumToString(value));
   first=false;
   return StringLen(EnumToString(value));

  }

enum keyword is not accepted. Using it breaks EnumToString function

uint CFileCsv::WriteElement(...)
  {
     // do something with var args ?

  }"

 

You should use enum as enum.

For example,

ENUM_CHART_MODE cm = CHART_BARS;
string cs = EnumToString( cm);
Print( "Chart mode:  " + cs);

// you get "CHARTS_BARS")

    
ENUM_POSITION_TYPE posType = POSITION_TYPE_BUY;
string  ps = EnumToString( posType );
Print( "Position type:  " + ps); 

//you get "POSITION_TYPE_BUY" 

You cannot define a generic function for enum, but you must specify the enum type.

For example, uint NewFunction( ENUM_POSITION_TYPE  posType); 

To add comments, please log in or register