MetaQuote's EA template of using GetPointer(...), bug or a feature?

 

 Hi, 

 I am an old time C++ programmer and just started learning MQL5. I notice the pointer concept of MQL5 is different from traditional C++, especially for getting pointer. I read the MQL5 document and quite easy to understand the concept of using function GetPointer(...) to get the pointer of a class object. However, I am getting confused when I see the Expert code from the sample code from Metaquote. The file is Expert.mqh which is used by all automatically generated EAs. Refer to the code highlighted in red, it is trying to get the pointer from a pointer variable. Base on my C++ knowledge, it sounds like getting a pointer's pointer. If that's the case, it is conflict with the function definition of SetSymbol(...) which expects a pointer, rather than pointer's pointer. 

Or it is a MQL5 feature that it treat class and class's pointer as the same way and still work as expected?  

Anyone could suggest it is the right logic here? or a bug of the sample code... Thanks!

in ExpertBase.mqh 

bool CExpert::InitTrade(ulong magic,CExpertTrade* trade=NULL)

  {

//--- 

   if(m_trade!=NULL) delete m_trade;

//---

   if(trade==NULL)

     {

      if((m_trade=new CExpertTrade)==NULL) return(false);

     }

   else m_trade=trade;

//--- tune trade object

   m_trade.SetSymbol(GetPointer(m_symbol));

   m_trade.SetExpertMagicNumber(magic);

   //--- set default deviation for trading in adjusted points

   m_trade.SetDeviationInPoints((ulong)(3*m_adjusted_point/m_symbol.Point()));

//--- ok

   return(true);

  } 

 

In expertBase.mqh 

   CSymbolInfo      *m_symbol;         // pointer to the object-symbol

In ExertTrade.mqh

bool CExpertTrade::SetSymbol(CSymbolInfo* symbol)

 
function GetPointer for pointer returns this pointer back

class CFoo { };
void OnStart()
  {
   CFoo foo,*pfoo=GetPointer(foo);
   Print(pfoo,"==",GetPointer(pfoo));
  }
of course optimizer of MQL5 compiler removes GetPointer call
Reason: