Did Structs Change with the last MT5 Update? - page 2

 
EntropyM #This is what I came up with as a fix, compiling without any errors or warnings now. @Fernando Carreiro I'm not sure if this was what you had in mind with the assignment operator and I still don't understand the exact difference between what you meant with "copy" and "assignment" being the same (but also not really), but is this at least somewhat close to what you had in mind? 

I too am a little confused because I seldom use the "assignment operator" methods myself, and even less the "copy constructor". So, my explanation was probably flawed. That is why I linked the C++ explanation to make it a bit more clear for you (and for me).

From your code, I can see that you implemented the "copy constructor" (and not the "assignment operator" as I originally suggested), and that seems to be the correct way as per the warning given by the compiler. I also learned something new with this, so you have my thanks.

 
EntropyM #:
@Vladislav Boyko well thats interesting since it already worked as intended before build 5200, and it still works on 5200, it just gives the warning on compile that it's deprecated and will be removed

MetaQuotes is currently improving the compiler and I am not sure how exactly MQL5 will change in the next release build. It is best to wait for the next release and read about the MQL5 changes in the release notes.

If you get a warning for only one structure (not several) and if that structure is not very large, then you can post the declaration of that structure and I will try to help you add an explicit "operator=" or an explicit copy constructor

 
Vladislav Boyko #:
If you get a warning for only one structure (not several) and if that structure is not very large, then you can post the declaration of that structure and I will try to help you add an explicit "operator=" or an explicit copy constructor

But it's likely that starting with the next release build, the compiler will automatically add both an implicit copy constructor and an implicit 'operator='. If so, that would make their explicit versions optional in most cases.

 

I think the following proves that in build 5222 the compiler generates an implicit copy constructor:

class A
  {
public:
   string toString() { return StringFormat("x = %i, y = %i", x, y); }
   
   void operator=(const A&) = delete;
   
private:
   const int x;
   const int y;
public:
   A(int a_x, int a_y) : x(a_x), y(a_y) {}
   
   A() : x(0), y(0) {}
  };

void OnStart()
  {
   A a1(56, 78);
   A a2 = a1;
   Print("a1:\n", a1.toString(), "\na2:\n", a2.toString());
  }


Below is a quote from the documentation, which demonstrates the explicit and implicit way of calling the copy constructor (do not confuse explicit/implicit call with explicit/implicit constructor)

https://www.mql5.com/en/docs/basis/types/classes#constructor

class CFoo
  {
   datetime          m_call_time;     // Time of the last object call
public:
   //--- Constructor with a parameter that has a default value is not a default constructor
                     CFoo(const datetime t=0){m_call_time=t;};
   //--- Copy constructor
                     CFoo(const CFoo &foo){m_call_time=foo.m_call_time;};
 
   string ToString(){return(TimeToString(m_call_time,TIME_DATE|TIME_SECONDS));};
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
// CFoo foo; // This variant cannot be used - a default constructor is not set
//--- Possible options to create the CFoo object
   CFoo foo1(TimeCurrent());     // An explicit call of a parametric constructor
   CFoo foo2();                  // An explicit call of a parametric constructor with a default parameter
   CFoo foo3=D'2009.09.09';      // An implicit call of a parametric constructor
   CFoo foo40(foo1);             // An explicit call of a copy constructor
   CFoo foo41=foo1;              // An implicit call of a copy constructor
 
Vladislav Boyko #:

I think the following proves that in build 5222 the compiler generates an implicit copy constructor:


Below is a quote from the documentation, which demonstrates the explicit and implicit way of calling the copy constructor (do not confuse explicit/implicit call with explicit/implicit constructor)

This is very interesting since if I try to run exactly your Class A code, I get the assignment operator being deprecated warning as well as a compilation error "attempting to reference deleted function 'void A::operator=(const A&)'" at line 20 with hints "function 'void A::operator=(const A&)' was explicitly deleted here" and "see declaration of function 'A::operator='". Maybe try running this code on a current release build terminal with 5200, the beta might be allowing things that are not defined and might even lead to some bugs and errors down the line.

 
EntropyM #:

the beta might be allowing things that are not defined and might even lead to some bugs and errors down the line.

The beta version contains new compiler improvements (not present in the 5200 release). But don't rush to update the terminal, as the beta version has a higher probability of bugs.

EntropyM #:
Maybe try running this code on a current release build terminal with 5200
I only have one copy of MT5 (beta version) but I can get the compilation errors you mentioned in MT4