Compile Error when use template in Class inheritance

 

Need help. When I migrate my mql4 lib to mql5, but come to a problem I can't solve. here is the code that recreate the problem.

template<typename T>
class Foo{};

template<typename T>
class Bar:public Foo< T >{};

void OnStart()
{
   Bar<int> b;
   Bar<Foo<int>> b2;
   Bar<const Foo<int>* > b3;
   Foo<const void *> f;
   // here is the problem: when set the tmplate type in Bar to "const void *", some compile error
   // 'T' - unexpected token
   // '<' - wrong template parameters count
   Bar< const void* > b4;
}

But I do need this language property in my library. Can anyone help me?


 

This might Compile 

/*
template <typename T>
class Foo{};

template <typename barT,typename fooT>
class Bar:public Foo<fooT>{};

void OnStart()
{
   Bar<int,int> b;
   Bar<void*,int> b2;
   Bar<void*,const int> b3;
   Foo<const void *> f;
   // here is the problem: when set the tmplate type in Bar to "const void *", some compile error
   // 'T' - unexpected token
   // '<' - wrong template parameters count
   Bar<const void *,Foo<const void *>> b4;
}
*/
template<typename T>
class Foo{};

template<typename T>
class Bar:public Foo< T >{};

void OnStart()
{
   Bar<int> b;
   Bar<Foo<int>> b2;
   Bar<const Foo<int>* > b3;
   Foo<const void *> f;
   // here is the problem: when set the tmplate type in Bar to "const void *", some compile error
   // 'T' - unexpected token
   // '<' - wrong template parameters count
   Bar<Foo<const void*>> b4;
}


 

 
Lorentzos Roussos:

This might Compile 


 

It will not work anyway with a real implementation. void pointer are not allowed in mql.
 
Alain Verleyen:
It will not work anyway with a real implementation. void pointer are not allowed in mql.

 curious what the OP needs it for though (first thought was a custom charting library )

 
Lorentzos Roussos:

 curious what the OP needs it for though (first thought was a custom charting library )

Ah, Bar Foo are not real specifications ?
 
Alain Verleyen:
Ah, Bar Foo are not real specifications ?

Dont laugh , you may be seeing a molecule from the holy grail itself :D 

 
Alain Verleyen:
It will not work anyway with a real implementation. void pointer are not allowed in mql.


class Foo{};
long GetAddress(const void *pointer)
{
    return long(StringFormat("%I64d",pointer));
}

void OnStart()
{
   Foo* f = new Foo;
   Print(GetAddress(f));
   delete f;
}
this works
 
Lorentzos Roussos:

 curious what the OP needs it for though (first thought was a custom charting library )

I'm wrinting a SharedPointer class, need a global pointer counter container to storage the pointer reference counter, and this container is something like HashMap<void *, int>.

it works in Mql4, but failed when migrate to Mql5.

 
Xiaowei Yan:


this works

I was curious to know since when this undocumented (to my knowledge) feature is available : it's actually very old (Build 1395 2016.08.18), I completely missed that.

Thank you very much.
List of changes in MetaTrader 5 Client Terminal builds
List of changes in MetaTrader 5 Client Terminal builds
  • 2015.10.29
  • www.mql5.com
List of changes in the Help for MQL5:Corrected description of the GlobalVariablesFlush() function , input parameters are not required, Length the c...
 
Xiaowei Yan:

I'm wrinting a SharedPointer class, need a global pointer counter container to storage the pointer reference counter, and this container is something like HashMap<void *, int>.

it works in Mql4, but failed when migrate to Mql5.

Hmm, im not that advanced ,so the goal is to be able to instantiate global class objects from within functions on runtime ?

 
Xiaowei Yan:

I'm wrinting a SharedPointer class, need a global pointer counter container to storage the pointer reference counter, and this container is something like HashMap<void *, int>.

it works in Mql4, but failed when migrate to Mql5.

Reported to Russian forum for more visibility.