How to duplicate objects like CObject???

 

Hi

CObject *o1 = new CObject();
CObject *o2 = o1;

o1 and o2 are now referring to the same object - that is the proper way, I'm not complaining.

But how do I copy an Object? 

 

thank you

 
dck:

Hi

o1 and o2 are now referring to the same object - that is the proper way, I'm not complaining.

But how do I copy an Object? 

 

thank you

via copy constructor or operator overloading. see e.g.

https://www.mql5.com/en/docs/basis/types/classes

 

Documentation on MQL5: Language Basics / Data Types / Structures and Classes
  • www.mql5.com
Language Basics / Data Types / Structures and Classes - Documentation on MQL5
 
investeo:

via copy constructor or operator overloading. see e.g.

https://www.mql5.com/en/docs/basis/types/classes

 

This still means doing it by hand for every property, right?
There is no copy() or clone() to do the work for me, (risking to forget a property) ?

like:

CObject(const CObject &obj){u=obj.u;
                            v=obj.v;
                            w=obj.w;
                            ...
};

 

Reason: