Download MetaTrader 5

Object Oriented

To add comments, please log in or register



I come from Java background so apologies if this question is obvious to c/c++  peeps. I have two objects BaseObject and SecondObject . SecondObject is initialised with a  parametrised constructor containing BaseObject or in this world a pointer/reference not the object itself like i do in java. My problem is when i do this i cannot let a local object (to secondobject) instance  = the passed in reference or contents of passed in reference. I have to extract the value and set that = to locala  variable e.g.  localobject = passedInreferenceToObject; is BAD localVAriable= passedInreferenceToObject.getValueOfSomething() is GOOD

My question is why can i not do this? Is it possible to initialise another copy of the passed in object reference?


class SecondObject





   //BaseObject bobj;                  

   //BaseObject     bobj2;                 

   double           bobjVal;                

   double            bobj2Val;               



 //--- An empty  default constructor

                     SecondObject() {Print(__FUNCTION__);};

   //--- A constructor with an initialization list

                     SecondObject(BaseObject  &_bobsen, BaseObject  &_bobsen2, string _desc){ bobjVal=_bobsen.getValue(); bobj2Val=_bobsen2.getValue(); };

                 // this causes compile error   

                // { bobj=_bobsen; bobj2=_bobsen2; }; 

   double            calculate();                 

   double            getValue(){return value;};

   string            getDescription(){return desc;};

Ex Ovo Omnia
Ex Ovo Omnia  
If you come from Java, then it would be much easier for you to stick to "pointers" like BaseObject* bobj2, because they actually operate the way you know instances in Java. You can live long time without using a single C++ "object", which does not have similar equivalent in Java.
To add comments, please log in or register