Errors, bugs, questions - page 1982

 
fxsaber:

The default copy operator is triggered.

If it's not difficult, where can I read it?

 

Can you tell me how to read information from an email or sms using MQL4/5? For example, I receive information-signal to email, my Expert Advisor reads it and opens/closes position.

 
fxsaber:

The default copy operator is triggered.

I even found this in the docs (note the 3rd line from the bottom):

https://www.mql5.com/ru/docs/basis/types/casting

class CBar { };
class CFoo : public CBar { };
 
void OnStart()
  {
   CBar bar;    
//--- динамическое приведение типа указателя *bar к указателю *foo разрешено 
   CFoo *foo = dynamic_cast<CFoo *>(&bar); // критической ошибки выполнения не возникнет   
   Print(foo);                             // foo=NULL      
//--- попытка явного приведения ссылки объекта типа Bar к объекту типа Foo запрещено
   foo=(CFoo *)&bar;                       // возникнет критическая ошибка выполнения
   Print(foo);                             // эта строка не будет выполнена
  }

I remember that it was possible to copy (in memcpy style) to simple structures, but my structure is not simple.

 
pavlick_:

I remember it was possible to copy (dumb memcpy style) into simple structures, but I don't have a simple structure.

MQL5 has changed.

 
fxsaber:

MQL5 has changed.

Forum on trading, automated trading systems and testing trading strategies

The new version of MetaTrader 5 build 1640: Create and test your own financial instruments

MetaQuotes Software Corp., 2017.07.19 18:03

New version of the MetaTrader 5 platform build 1640: creating and testing your own financial instruments

  1. MQL5: Added automatic generation of implicit copy operator for objects of structures and classes. Now the compiler automatically generates copy operators, which allows to write simple records for objects like b=a:
    class Foo
      {
       int               value;
    public:
       string Description(void){return IntegerToString(value);};
       //--- конструктор по умолчанию
                         Foo(void){value=-1;};
       //--- конструктор с параметрами   
                         Foo(int v){value=v;};
      };
    //+------------------------------------------------------------------+
    //|  структура, содержащая объекты типа Foo                          |
    //+------------------------------------------------------------------+
    struct MyStruct
      {
       string            s;
       Foo               foo;
      };
    //+------------------------------------------------------------------+
    //| Script program start function                                    |
    //+------------------------------------------------------------------+
    void OnStart()
      {
    //---
       MyStruct a,b;
       Foo an_foo(5);
       a.s="test";
       a.foo=an_foo;
       Print("a.s=",a.s," a.foo.Description()=",a.foo.Description());
       Print("b.s=",b.s," b.foo.Description()=",b.foo.Description());
    //---
       Print("b=a");
       b=a;
    //---
       Print("a.s=",a.s," a.foo.Description()=",a.foo.Description());
       Print("b.s=",b.s," b.foo.Description()=",b.foo.Description());
    /*
       Результат выполнения;
       a.s=test a.foo.Description()=5
       b.s= b.foo.Description()=-1
       b=a
       a.s=test a.foo.Description()=5
       b.s=test b.foo.Description()=5
    */
      }
    The implicit operator copies objects by heart.

    • If a member is an object, the copy operator corresponding to this object is called.
    • If the member is an array of objects, before calling the appropriate copy operator for each element, the receiving array is enlarged or reduced to the required size via ArrayResize.
    • If a member is an array of simple types, the ArrayCopy function is used for copying.
    • If a member is a pointer to an object, the pointer itself is copied, not the object it points to.

    If necessary, you can override the behaviour and create your own variant instead of the implicit copy operator using overloading.
 

fxsaber

Thank you, that makes sense now. Don't know whether to rejoice or not. The compatibility with the old code is broken. It's a good idea to somehow force activation of new functionality with such significant changes (via compilation switches or #pragma).


For example, my auto_ptr:

template <typename T_>
class auto_ptr
{
public:
   T_ *p;
   void reset()  {if(this.p) delete this.p; this.p=NULL;}
   auto_ptr(void *ptr=NULL): p(ptr)  {}
   ~auto_ptr()  {this.reset();}
   void swap(auto_ptr<T_> &other)
   {
      T_ *buf = this.p;
      this.p = other.p;
      other.p = buf;
   }
};

Now it turns out that auto_ptr can be copied in the new code (unless the copying operator/constructor is silenced), which will lead to multiple deletions of a single pointer.

 
 

File MQL5\Include\Controls\SpinEdit.mqh

int MaxValue(void) const { return(m_min_value); }

 

How do I download MT4?
I download the mt4setup.exe file, install it, but the platform installs mt5. where can I get mt4?

 
lukyF: How do I get MT4?

I download the mt4setup.exe file, install it, but the platform installs mt5. where can I get mt4?

You can download mt4 from your broker. This question comes up every week...
Reason: