OOP, templates et macros dans mql5, subtilités et utilisations - page 22

 
fxsaber:

Merci !

Mais je n'ai pas trouvé comment remplacer la macro.

Voici le code :

#define  MACROS_PREFIX(A) FAST_##A

bool Connect(string host = "localhost", int port = 6379)
   {
   return(MACROS_PREFIX(connect)(host, port));
   }

   
   
bool FAST_connect(string host = "localhost", int port = 6379)
{
return true;
}

bool connect(string host = "localhost", int port = 6379)
{
return true;
}

cela fonctionne maintenant, mais avec le préfixeFAST_ , je veux passer outreMACROS_PREFIX , mais pour queconnect(string host = "localhost",int port = 6379) soitappelé

 
Igor Makanu:

Je veux remplacerMACROS_PREFIX mais appelerconnect(string host = "localhost", int port = 6379)

#undef  MACROS_PREFIX
#define  MACROS_PREFIX(A) A
 
Igor Makanu:

Merci !

Mais je n'ai pas trouvé comment remplacer la macro.

Voici le code :

cela fonctionne maintenant, mais avec le préfixeFAST_ , je veux passer outreMACROS_PREFIX , mais pour queconnect(string host = "localhost", int port = 6379) soitappelé

#define  F_CALL(dPrefix,dFunc) dPrefix##_##dFunc

void Foo()  {Alert("Null");}
void _Foo() {Foo();}
void SomePref_Foo()  {Alert("SomeFunc");}

void OnStart(){
   F_CALL(,Foo)();
   F_CALL(SomePref,Foo)();
}
 

Il est étrange que cela fonctionne, mais ce n'est pas le cas.

F_CALL()
 
fxsaber:

C'est étrange que ça marche, mais ça ne marche pas.

Ma macro a deux paramètres, mais vous n'en passez qu'un, donc le compilateur jure.

 

merci... mais je ne l'ai toujours pas compris.... la science de l'enfer !!!!

Je ne peux pas l'expliquer avec des mots. Je vais essayer en langue des signes.

Ce code fonctionne comme prévu :

bool USE_SAVE_MODE = true;                      // проверка пинга
bool ping() { return(true); }                   // заглушка 
bool connect(string h,int p) { return(true);}   // заглушка 
//+------------------------------------------------------------------+
bool ExPing()
   {
   if(USE_SAVE_MODE)
      {
      Print("safe mode on");
      return(ping());
      }
   else
      {
      Print("safe mode off");
      return(true);
      }

   }
//+------------------------------------------------------------------+
bool Connect(string host = "localhost", int port = 6379)
   {
   return ExPing() && connect(host, port);
   }

//+------------------------------------------------------------------+
void OnStart()
   {
      Connect();
      USE_SAVE_MODE = false; // отключили проверку пинга
      Connect();
   }
//+------------------------------------------------------------------+

Mais je veux faire une substitution de macro dans MQL pour minimiser le texte du code lui-même, donc j'en ai besoin :

#define   USE_FAST                               // тут нужно что-нибудь сделать!
bool connect(string h,int p)      {    }        // код 1
bool fast_connect(string h,int p) {    }        // код 2
//+------------------------------------------------------------------+
bool Connect(string host = "localhost", int port = 6379)
   {
   return connect(host, port);                  // вот тут нужен префикс и будет или connect(host, port);  или fast_connect(host, port); 
   }

//+------------------------------------------------------------------+
void OnStart()
   {
      Connect();
   }
//+------------------------------------------------------------------+
 
Vladimir Simakov:

Ma macro a deux paramètres et vous n'en passez qu'un seul, c'est pourquoi le compilateur se dispute

Ça ne marche pas.

   F_CALL(,)
 
fxsaber:

Ça ne marche pas.

Bien sûr que oui. Vous l'avez en expansion dans _
 
Igor Makanu:

merci... mais je ne l'ai toujours pas compris.... la science de l'enfer !!!!

Je ne peux pas l'expliquer avec des mots. Je vais essayer en langue des signes.

Ce code fonctionne comme prévu :

mais je veux faire une substitution de macro dans MQL pour minimiser le texte du code lui-même, donc j'en ai besoin :

#define   USE_FAST                               // тут нужно что-нибудь сделать!
#ifdef  USE_FAST
   #define  CONNECT fast_connect
#else
   #define  CONNECT connect
#endif
bool connect(string h,int p)      {    }        // код 1
bool fast_connect(string h,int p) {    }        // код 2
//+------------------------------------------------------------------+
bool Connect(string host = "localhost", int port = 6379)
   {
   return CONNECT(host, port);                  // вот тут нужен префикс и будет или connect(host, port);  или fast_connect(host, port); 
   }
//+------------------------------------------------------------------+
void OnStart()
   {
      Connect(...);
   }
//+------------------------------------------------------------------+

MAIS ! !!

La macro CONNECT ne peut pas être surchargée en faisant #undef USE_FAST

 

pour que je puisse faire ce que je veux.

#define   USE_FAST
bool connect(string h,int p)      { Print("On");   return true; }
bool fast_connect(string h,int p) { Print("Off");   return true;}
//+------------------------------------------------------------------+
bool Connect(string host = "localhost", int port = 6379)
   {
   #ifdef  USE_FAST
   return connect(host, port);
   #else return fast_connect(host, port);
   #endif 
   }

//+------------------------------------------------------------------+
void OnStart()
   {
      Connect();
   }
//+------------------------------------------------------------------+


intéressé par les options suggérées hier par la formule magique #defaine abracadabra ##_

UPD :

Vladimir Simakov OK, je vais essayer de trouver une solution.

UPD :

HOORAY ! ÇA A MARCHÉ ! (С)

#define   USE_FAST
#ifdef  USE_FAST
   #define  CONNECT fast_connect
#else
   #define  CONNECT connect
#endif

bool connect(string h,int p)      { Print("On");   return true; }
bool fast_connect(string h,int p) { Print("Off");   return true;}
//+------------------------------------------------------------------+
bool Connect(string host = "localhost", int port = 6379)
   {
   return CONNECT(host, port);
   }

//+------------------------------------------------------------------+
void OnStart()
   {
      Connect();
   }
//+------------------------------------------------------------------+


Merci ! Ça a marché comme prévu !


PZY : Comment ajouter les macros __MQL5__ et __MQL4__ à cet abracadabra, mais les fonctions fast_xxx() ne seront jamais dans le code MQL4 du tout - du mot JAMAIS

Raison: