Errors, bugs, questions - page 2473

 
Sergey Dzyublik:


Currently it is not possible to use a static variable declared inside a template class.
With the introduction of a namespace, could this restriction be bypassed?

Yes, you can.

The code will be slightly different, more correct, here is an example:

//+------------------------------------------------------------------+
//|                                                  ScopeSample.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
template<typename T>
class A
  {
public:
   struct Item
     {
      T                 value;
      
      Item(T initial=10):value(initial) { Print(__FUNCSIG__); }
     };

   static Item       s_default;
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
template<typename T>
class B
  {
public:
   struct Item
     {
      T                 value;
      
      Item(T initial=100):value(initial) { Print(__FUNCSIG__); }
     };

   static Item       s_default;
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
template<typename T>
A::Item A::s_default;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
template<typename T>
B::Item B::s_default;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   Print(A<int>::s_default.value);
   Print(B<int>::s_default.value);
  }
//+------------------------------------------------------------------+


Result:

2019.05.24 17:16:20.225 ScopeSample (EURUSD,H1) A<int>::Item::Item(int)
2019.05.24 17:16:20.225 ScopeSample (EURUSD,H1) B<int>::Item::Item(int)
2019.05.24 17:16:20.225 ScopeSample (EURUSD,H1) 10
2019.05.24 17:16:20.225 ScopeSample (EURUSD,H1) 100
 
Very cool, thank you very much.
Is it possible to get alpha access to MT with namespace support?
Really need as part of a study to be able to write a "smart container", not to look for bugs/vulnerabilities etc.
 

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Sergey Dzyublik, 2019.05.23 13:52

I've been working with my broker for the last time, and I've found out about a dozen of bugs and "peculiarities" in MT.
How to know whether it's worth waiting for them to be fixed or not?
Please don't suggest testing everything every time a new build comes out.

(not fixed in MT5(build 2059))"Compilation error when passing (void*)(NULL) parameter to template function".
(fixed in MT5(build 2059)) "Strategy tester: 2 passes planned, but in practice infinite number of passes > 900pc due to "OnInit critical error" error".
(not fixed in MT5(build 2059))"Invalid value of array size field within default assignment operator for structures with dynamic arrays".
(not fixed in MT5(build 2059))"The compiler does not see the default class copy constructor when returning a class object by value from a function".
(fixed in MT5(build 2059)) "Compiler fails to see type cast "in itself" for pattern classes and "complex" structures".
(not fixed in MT5(build 2059))"When working with typedef, using a template function with explicit specialization does not generate code for this template function.
(not fixed in MT5(build 2059))"Compilation error when reusing the same function signature within typedef".
#
(not fixed in MT5(build 2059))"A significant part of functions for string handling doesn't work with NULL characters in a string (for example: ShortArrayToString, StringInit, StringFill)".
(not fixed in MT5(build 2059))"The StringSetLength function only works to "trim" the string length, not to increase it.
#(fixed in MT5(build 2057))"Strategy Tester: 750 "metatester64.exe" processes are running".
"Forum www.mql5.com, when editing a message with a picture, the previous picture is not replaced with the new one".


Suggestions:
"Allow user to force code generation/deletion for default assignment operator (copy constructor)".
"Allow ArrayCopy to copy classes and "complex" structures, similar to how structures provide deep copy functionality for any object type".
"Provide functionality for user to read/set Capacity value when working with dynamic arrays".

"Changes to improve infographics of the Signals service"


 

Today in my terminal the tick history on my real futures market account, broker Otkritie, is not being uploaded.

The data in the ticker is changing.

It is now 24.05.2019 23:40

The terminal has the last tick for 23.05.2019.


Same situation on some other instruments, including those I have traded myself.

On a second terminal (separate setup), on another account of the same broker the effect is the same.

 
Can you tell if an expert is working in optimisation mode or single test mode?
 
MT5 (build 2059)
Compilation error when passing (void*)(NULL) parameter to template function:
class C{
public:
   template<typename T>
   static void func(T ){
      Print(__FUNCSIG__);
   }
};


void OnStart(){  
   void* c_ptr = new C();
   
   C::func((C*)NULL);     // Ok
   C::func(c_ptr);        // Ok
   C::func((void*)NULL);  // 'void' - illegal use of 'void' type
   
   delete c_ptr;
}
Everything was working in (build 2057), maybe something got screwed up as part of the fix:
and#"Compilation error when executing type cast "itself" for template classes and "complex" structures".
 
Perhaps by analogy with C++ it makes sense to introduce a "full-fledged" nullptr pointer ?
 

Back in build 2056, everything worked fine. But in 2059 it already has a compilation error:

void OnStart()
{
class A {};
//#define void  A //(*)
        const void *p1;
              void *p2 = (void *)p1; //Error: 'void' - class type expected
}

And if we replace void with A (*), everything is ok. What difference does it make?

Moreover, a compilation error occurs even in this case:

              void *p2 = (void *)p1; //Error: 'void' - class type expected
 

When compiling in command build 2059x32 abstract error:

but does not reproduce via IDE - could be an accident

 
A100:

How do you choose between using templates and void* ?

Reason: