[CLOSED] : Compiler bug with template parameter = void*

 

Compiler error. Bild 1961, 64 bit.

template<typename T>
class A
{ 
};

A<void*> a;  // '<' - cannot to apply function
 
Was it possible before?
 
I'll check on this announcement with C++ in the evening
 
Vladimir Simakov:
Was it possible before?

Yes. I checked it specially on old build (1554) - everything works.

I'll check it tonight with such announcement in C++.

Well, it's certainly OK there. Is there any reason why it may not work?
 
Alexey Navoykov:

Please give an example of the use of this construction.

 
fxsaber:

Please give an example of how to use this construct.

The most trivial example is an array class. In this case it is used to store any pointers:

template<typename T>
class CArray
{
  T _data[]; 
 public:
  T operator[](int i) const { return _data[i]; }
  int Size()          const { return ArraySize(_data); }
  // и т.д.
};

СArray<void*> pointers;
 
Alexey Navoykov:

The most trivial example is the array class. In this case it is used to store any pointers.

How to use it then?

class A
{
public:
  void OnInit()
  {
    Print(__FUNCSIG__);
  }
};

class B
{
public:
  void OnInit()
  {
    Print(__FUNCSIG__);
  }
};

void OnStart()
{    
  void* Pointers[2];

  A a;
  B b;
  
  Pointers[0] = &a;
  Pointers[1] = &b;
  
  for (int i = 0; i < ArraySize(Pointers); i++)
    Pointers[i].OnInit(); // 'OnInit' - member function not defined
}
 
fxsaber:

How to use it then?

The same way as for example CObject is used in metaquote containers. Cast to the type you put there initially (or use dynamic_cast to check). It's a bit surprising to hear you ask this question.
 
Alexey Navoykov:
Cast to the type you put there originally (or check via dynamic_cast).
//    (A*)Pointers[i].OnInit();
    ((A*)Pointers[i]).OnInit();

This is just on the subject of whether brackets are necessary/unnecessary... With this casting it would be a bummer in the script above when executed. I.e. you need to know the names of the classes that the array pointer elements refer to.

I don't see what the convenience is then.


MQ only uses void* in one place.

typedef string(*DoubleToStringFunction)(double,void*);
 
fxsaber:

MQ only uses void* in one place.

Because they have everything built on CObject, it makes it impossible to use their containers for their own classes and interfaces, not inherited from their class. I.e. not a universal solution.

This is probably due to the fact that at the time of creation of their library there wasn't void* in MQL yet. But on the other hand their object itself also takes part in some manipulations (changing values of pointers in it), which in itself is just wild.

 
Alexey Navoykov:

This makes it impossible to use their containers for their own classes and interfaces not inherited from their class, i.e. not a universal solution.

Perhaps this is because at the time their library was created, there was no void* in MQL yet.

Unfortunately, I haven't seen an example of its use.

Reason: