Copy Objects on MQL4 works differently on MQL5

 

Hi all,

Inside a script i use the following code :



//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//-
   TestClass test1,test2;
   
   test1.name = "Name1";
   test2.name = "Name2";
   
   test1.printName();
   test2.printName();
   
   test1 = test2;
   
   test1.printName();

                      
  }
//+------------------------------------------------------------------+

class TestClass
{
   public:
      string name;
      void printName(){Print(this.name);}
};


This above code works correctly in MQL5 but in MQL4 creates a compile error : '=' - structure have objects and cannot be copied

Even if i inheritance the class CObject into the TestClass creates another compile error : '=' - not allowed for objects with protected members or inheritance

Example with CObject inheritance :

#include <Object.mqh>

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//-
   TestClass test1,test2;
   
   test1.name = "Name1";
   test2.name = "Name2";
   
   test1.printName();
   test2.printName();
   
   test1 = test2;
   
   test1.printName();

                      
  }
//+------------------------------------------------------------------+

class TestClass : public CObject
{
   public:
      string name;
      void printName(){Print(this.name);}
};

Even if i replace the string property with int the compile error still exist.

In this example i don't want to use POINTER_DYNAMIC to solve the issue.

Why that happens only on MQL4 ? Can be solved without using pointers ? Please advise.

Thanks in advance!






Reason: