0
votes

I've got the following MQL code:

class Account {};

class Trade {

  protected:

    struct TradeParams {
      uint     slippage;   // Value of the maximum price slippage in points.
      Account *account;    // Pointer to Account class.
    };

    TradeParams trade_params;

  public:

     void Trade(TradeParams &_params) {
       trade_params = _params; // Error: '=' - structure have objects and cannot be copied.
     }

};

However, the MetaTrader platform doesn't compile the file due to the following error:

'=' - structure have objects and cannot be copied TestTrade.mqh 17 21

I'm using MetaEditor 5.00 build 1601 (May 2017).

I've checked this similar question, but my struct doesn't contain any complex objects such as strings. The suggestion is to use pointers instead of structures, which I am actually using. My goal is to have a class constructor with a struct argument as shown above.

What is wrong with above struct definition and how it can be corrected?

2

2 Answers

1
votes

You should use structures in structures or classes in classes in MQL4/5. So, either:

struct Account {int m_accountNumber; };
struct TradeParameters {uint m_slippage; Account m_account; };
struct Trade {protected: TradeParameters m_tradeParam; public : };

or same with classes. Classes are preferred because you cannot have strings as structure members (you will have problems with copying and other manipulations).

0
votes

It seems this compiling issue has been fixed in the recent version of the platform.

I've compiled the same code under MetaEditor v5.00 build 1745 and it worked fine.