Using new operator?

 

The code generated by EA generator MT5 includes definitions of object pointer for example :

CExpertSignal *signal = new CExpertSignal;


Why not use this method?

CExpertSignal signal;


What is the reason for using the new operator?
 
The second code is creating an object directly on the stack of the function. When passing this object to a function, a copy of the object is created on the stack of the called function.

When the called function alters the object, it changes only the local copy.

A pointer points to an object created on the heap memory of the process, therefore it referes to the same object.

To achieve same you can pass the object (from stack) to a function which uses a reference as input.







 
Overweight:

The code generated by EA generator MT5 includes definitions of object pointer for example :


Why not use this method?


What is the reason for using the new operator?

Just place the cursor of the editor on new and press F1 - you'll directly forwarded to the doc. of the MQL functions.