Class instance assignment

 

In MQL4, consider code below:

class CObject
{
        private:
                int m_state;
        public:
                void SetState(int state) { m_state = state; }
}

CObject A, B;

A.SetState(0);
B.SetState(1);

B = A;
A.SetState(3);

After this, I assume that B's m_state value will be 0, and A's m_state will be 3. Am I correct in my assumption ?

 
Bondan Sebastian:In MQL4, consider code below: After this, I assume that B's m_state value will be 0, and A's m_state will be 3. Am I correct in my assumption ?

Why not simply test it and find out?

Part of the fun of learning is to test things out and figure out how they work.

 

MQL5: Added automatic generation of an implicit copy operator for the objects of structures and classes. Now, the compiler automatically creates copy operators, which allows writing simple entries for objects, such as b=a:
          MetaTrader 5 Platform Beta Build 1625: Custom financial instruments - Stock Option Trading Strategies - General - MQL5 programming forum№ 8 2017.06.29

Note that we did not have to overload the assignment operator "=", as structures of simple types can be directly copied one into each other. Thus, we can now write a code for calculations involving complex numbers in the usual manner.
          Language Basics / Functions / Operation Overloading - Reference on algorithmic/automated trading language for MetaTrader 5
          Operation Overloading - Functions - Language Basics - MQL4 Reference