MQL4 Documentation: Modifier '&' and Keyword 'this'
Passing Parameters by Reference
&):** Added before the parameter name in the function header to indicate passing by reference. Changes to the parameter inside the function affect the original variable.const modifier with & (e.g., const double &array[]) to prevent changes to parameters passed by reference.& symbol is obligatory when passing arrays and structures as function parameters.**Example:**
class CDemoClass {
private:
double m_array[];
public:
void setArray(double &array[]);
};void CDemoClass::setArray(double &array[]) {
if(ArraySize(array) > 0) {
ArrayResize(m_array, ArraySize(array));
ArrayCopy(m_array, array);
}
}
Keyword this
this always refers to the object whose method is being executed.GetPointer(this) returns a pointer to the current object.GetPointer(this) (e.g., CDemoClass *getDemoClass() { return(GetPointer(this)); }).new and delete cannot be applied to structures.
* GetPointer(this) cannot be used within structure methods.**Example:**
class CDemoClass {
private:
double m_array[];
public:
void setArray(double &array[]);
CDemoClass *getDemoClass();
};CDemoClass *CDemoClass::getDemoClass(void) {
return(GetPointer(this));
}