Some inheritance issue\bug? was working ...help

 

Hi Guys,

I'm back into MQL4 after a year of work again (my normal pattern) and found my trading library I've worked all these years (written in MQL5 then rewritten to MQL4...and I think back to MQL5 again and again to MQL4 LOL anyway....hard work) doesn't work again, however it was working when i stopped last year...

Anayway the issue is:

In the code snipplet example below I have ObjectB deriving from ObjectA. My ExpertObject class below takes a ObjectA into its constructor. As you can see I passed a ObjectB because ObjectB derives from ObjectA. In the passed it would have passed ObjectB through to the ExpertObject's constructor NOW it Passes ObjectA instead and not the derived ObjectB. Please check it out using the watcher while debugging, this was never an issue. Was this a fix that broke my code LOL

or is this a bug...?? or

Am I doing something wrong? 

I'm using MICTrader4 version 4 build 902 

#property copyright "Ernie Gunning"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
#include <OwnObjects\OOLib\OrderInfo.mqh>
void OnStart()
  {
//---
   ObjectB *b = new ObjectB();
   b.Init();
   ExpertObjects *expert = new ExpertObjects(b);
   int breakpoint =0;
  }
//+------------------------------------------------------------------+

  class ObjectA
  {
  private:
  
      string test;
   public:
                     ObjectA(void){ 
                     test = "Object A Created";
                     };
                    ~ObjectA(void);
                    int virtual Init(){
                    string init ="Initialized ObjectA";
                    return INIT_SUCCEEDED;}; 
  };


class ObjectB : ObjectA
  {
  private:
  
      string test;
   public:
                     ObjectB(void){ 
                     test = "Object B Created";
                     };
                    ~ObjectB(void);
                    int virtual Init(){
                    ObjectA::Init();
                    string init ="Initialized ObjectB";
                    return INIT_SUCCEEDED;}; 
  };
  
  

  
  class ExpertObjects
    {
  public:
                       ExpertObjects(ObjectA *objectA)
                       {
                       
                       string StringA = "objectA should be of type ObjectB, ObjectB was passed in and it derived (inherit) from ObjectA. Use watch in realtime to see.";
                       };
                      ~ExpertObjects(void);
    };
 
Ernie Gunning:

Hi Guys,

I'm back into MQL4 after a year of work again (my normal pattern) and found my trading library I've worked all these years (written in MQL5 then rewritten to MQL4...and I think back to MQL5 again and again to MQL4 LOL anyway....hard work) doesn't work again, however it was working when i stopped last year...

Anayway the issue is:

In the code snipplet example below I have ObjectB deriving from ObjectA. My ExpertObject class below takes a ObjectA into its constructor. As you can see I passed a ObjectB because ObjectB derives from ObjectA. In the passed it would have passed ObjectB through to the ExpertObject's constructor NOW it Passes ObjectA instead and not the derived ObjectB. Please check it out using the watcher while debugging, this was never an issue. Was this a fix that broke my code LOL

or is this a bug...?? or

Am I doing something wrong? 

I'm using MICTrader4 version 4 build 902 

I assume the inheritance must be public to get detected.

 class ObjectB : public ObjectA

 
Ovo Cz:

I assume the inheritance must be public to get detected.

 class ObjectB : public ObjectA

Thanks Ovo for your response. Very valid assumption. i have tried it but still receiving ObjectA in the ExpertObject constructor.

anyway still stuck....

 

To the MQL4 forum, Please help here as I dont want to be forsced to re-write my strategy without the reuse of OO. This feature I need.

 

I also tried to create a ObjectA in ExpertObject as public and setting it however it cant as well as it sees them as two different objects... 

 
You can take help from docs section also. try it :)
 
Khurram Mustafa:
You can take help from docs section also. try it :)

Thanks have done so many times :) to make sure my bad English understanding has not missed something.

 Inheritance: https://docs.mql4.com/basis/oop/inheritance 

Inheritance - MQL4 Documentation
  • docs.mql4.com
Inheritance - MQL4 Documentation
 
I just tested this in MQL5...same issue
 

Ok I got feedback from Support,

 

Ovo was right on the "Inheritance type" that should be specified. Support came back and said the default should've been "public" but it is "private". They will fix this. What lead me to believe it was still broken after changing it to "public (as per Ovo suggestion) was that the watcher still showed ObjectA in the constructor of Expertobject. Support confirmed that the watcher will show the object type of the constructor parameter and NOT the object passed in (objectB). So they where saying the although the watcher is saying I have a ObjectA, I in fact had a ObjectB. I tested this with 2 adjustment in the code below. In ExperObject constructor called objectA.Init and it launched ObjectB.init(). I hope they fix the Watcher to show the correct object....

 Thanks Guys and support!

 

#property copyright "Ernie Gunning"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
#include <OwnObjects\OOLib\OrderInfo.mqh>
void OnStart()
  {
//---
   ObjectB *b = new ObjectB();
   b.testA = "testA";
   b.testB = "testB";
   ExpertObjects *expert = new ExpertObjects(b);
   int breakpoint =0;
  }
//+------------------------------------------------------------------+

  class ObjectA
  {

   public:
   string testA;
                     ObjectA(void){ 
                     testA = "Object A Created";
                     };
                    ~ObjectA(void);
                    int virtual Init(){
                    string init ="Initialized ObjectA";
                    return INIT_SUCCEEDED;}; 
  };


class ObjectB : public ObjectA
  {

   public:
   string testB;
                     ObjectB(void){ 
                     testB = "Object B Created";
                     };
                    ~ObjectB(void);
                    int virtual Init(){
                    ObjectA::Init();
                    string init ="Initialized ObjectB";
                    return INIT_SUCCEEDED;}; 
  };
  
  

  
  class ExpertObjects
    {
  public:
                       ExpertObjects(ObjectA *objectA)
                       {
                       objectA.Init();
                       string StringA = "objectA should be of type ObjectB, ObjectB was passed in and it derived (inherit) from ObjectA. Use watch in realtime to see.";
                       };
                      ~ExpertObjects(void);
    };
 
Ernie Gunning:

Ok I got feedback from Support,

 

Ovo was right on the "Inheritance type" that should be specified. Support came back and said the default should've been "public" but it is "private". They will fix this. What lead me to believe it was still broken after changing it to "public (as per Ovo suggestion) was that the watcher still showed ObjectA in the constructor of Expertobject. Support confirmed that the watcher will show the object type of the constructor parameter and NOT the object passed in (objectB). So they where saying the although the watcher is saying I have a ObjectA, I in fact had a ObjectB. I tested this with 2 adjustment in the code below. In ExperObject constructor called objectA.Init and it launched ObjectB.init(). I hope they fix the Watcher to show the correct object....

 Thanks Guys and support!

 

I expect they won't fix it, to stay uniform with the C++ syntax. Anyway, the single-class inheritance has no real use for inheritance with private accessors, so changing the accessor default to public probably wouldn't spoil any finished code.

The watcher shows the declared type, not the instantiated type. I doubt there is a way to detect the instance type by means of MQL4 in general.

 
Ovo Cz:

The watcher shows the declared type, not the instantiated type. I doubt there is a way to detect the instance type by means of MQL4 in general.

I do remember this working in 2014 as my comments was complying with it as well... I'm really thinking hard to move to a C# alternative trading platform but they seem to not be so adopted yet...