Multiple inheritance - page 2

 

What are you trying to do?

If you want to have multiple dialogues, it won't work proper no matter what you do with the Control classes of the standard library. The root of the problem is CObject as well as CWnd. Once you have any workaround, you will encounter other problems, it will never work the way you want it to, because the signal flow of CWnd is not designed for multiple threads at all. The whole architecture of it is a disaster and already the examples do not work proper: 80-90% of your CPU is going to be used when you just move the mouse! 

If you need just interaction between classes, you could add a CObject pointer array to CObject itself where you can store pointers of other instances, and add virtual functions to CObject that handle functions for interactions, that definitely works.

Another solution is to add true multithreading to CObject. By this, you could implement OnInit(), OnChartEvent(), OnTick(), OnDeinit() and OnTimer in any instance, this is not such a big deal if you´re familiar with C++.

If there were more requests like this, I would have released my version of CObject already, which is able to provide multithreading. But the most programmers here don´t seem to work with OOP anyway. 

Doerk 

 

Sorry for the late response, it's more of a design architecture problem, i've used a bottom up architecture to access lower classes down the hierarchy, basically RiskManagement inherits Trader and Trader inherits Statistics, however i have a MakretIndicatorClass that needs to both access the same instance of the statistics class (which is being fed tick data OnTick()) and the Trader class so it can pass it various data and controls over which algorithms to run relative to market movement, variance and some abstract stuff ive defined. RiskManagement should be able to access both MarketStateIndicator and Trader (which ships statistics), so it can control and calculate some probabilities relative to the system and then modify lots, stops, trailing losses, takeprofit, the current running algorithm etc. 

 

I ended up passing the RiskManagement object to the MarketStateIndicator as a parameter of the constructor which is defined as the statistics object in the constructor.  For a dialogue I just declare RiskManagement object in global scope creating the other 4 objects.

 

I got a pretty good feeling i shouldnt be passing the object itself as the argument for the constructor but unless i dont delete the instance everything seems to function fine.

This is how it looks.  

class CRiskManagement : public CTrader
  {
  
  CTrader m_member;
  
private:

public:

CMarketIndicator *MI;                     
static int riskLevel;
static int algorithmA;                     
                     
                     CRiskManagement(void);
                    ~CRiskManagement(void);
                     void MoneyManagement();
                     static void RiskController();
                     void MeasureOfScuccess();
                     
                     
                    
                    
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CRiskManagement::CRiskManagement(void)
  {
  
      MI = new CMarketIndicator(this);
  }


class CMarketIndicator : public statistics
  {
  
   statistics *s; 

   private:
public:                     CMarketIndicator(statistics &Object){ s = &Object; timerset = 0;}                     ~CMarketIndicator(void);                      void MarketAnalyser();                      void UpMarket();                      void DownMarket();                      void Volitility();                      void ResetVars();                      void timing();                        };

 

Then i use static variables rather than a controller or such to pass the data between MarketIndicator and Trader, include header and use the "::" scope classifier in Trader. I was looking at an array of pointers but i only include the Dialogue class, i wasnt sure how to pass pointers between class files.  All header / class files are separate. My EA has 3 lines in OnTick() and just the dialogue initialization OnStart();

 

I recently heard of using a "Base Class" or file, but i've always been used to separating things in this sort of form. 

 
Ovo:

The work-around (or pattern from my point of view) which might be used is embedding the instance of the class into the instance of the other class type.

E.g. if you need Runnable instance for your logic, but your method is implemented in RunClass, create a wrapper (RunClassWrapper) and invoke your RunClass.operation() from within the RunClassWrapper.run() metod.

 

Two separate class/objects need a pointer to the same instance of another class, and these two classes also need to communicate (But i just used static variables, there arent many).

I've had a few flakey designs, this one is pretty simple for now, i don't know whether as a paradigm it's even close to being correct but it functions as i need for now.  

The Dialogues are hardest to work with in respect to them being chart objects, essentially stopping any multilateral use of a proper interface (but i'm not experienced enough to judge, just a basic non-dependant interface would be nice, like using a DLL into glib (or other c library))

I suppose you can export real time data out to any interface you want so its partially irrelevant. 

Regards. 

 
Keelan:

Two separate class/objects need a pointer to the same instance of another class, and these two classes also need to communicate (But i just used static variables, there arent many).

I've had a few flakey designs, this one is pretty simple for now, i don't know whether as a paradigm it's even close to being correct but it functions as i need for now.  

The Dialogues are hardest to work with in respect to them being chart objects, essentially stopping any multilateral use of a proper interface (but i'm not experienced enough to judge, just a basic non-dependant interface would be nice, like using a DLL into glib (or other c library))

I suppose you can export real time data out to any interface you want so its partially irrelevant. 

Regards. 

Actually, reading this, I do not think your problem is multiple inheritance.
 

Well if a controller could inherit an instance of both MarketState and Trader then it could relay the Statistics to the other, i would initiate controller via Riskmanager and wouldnt need to pass around objects or pointers to constructors to get the same instance. I know there's better ways, its just a quick fix.

 

As i say its probably my design flaw. I'm not particularly well versed in c++ and mql makes it harder.

 
ThreadHandle:

Not sure maybe java had more than extends? i forget. I think c# you can inherit base class + shared interface. 

Plus since starting mql I've made a few steps towards learning c++.

C# does not support multiple inheritance , because they reasoned that adding multiple inheritance added too much complexity to C# while providing too little benefit. In C#, the classes are only allowed to inherit from a single parent class, which is called single inheritance . But you can use interfaces or a combination of one class and interface(s), where interface(s) should be followed by class name in the signature.

Ex:
 
    Class FirstClass { }
    Class SecondClass { }
 
    interface X { }
    interface Y { }

You can inherit like the following:
 
class NewClass : X, Y { }

In the above code, the class "NewClass" is created from multiple interfaces.
 
class NewClass : FirstClass, X { }

In the above code, the class "NewClass" is created from interface X and class "FirstClass".
Why does C# doesn't support Multiple inheritance
  • net-informations.com
In C#, the classes are only allowed to inherit from a single parent class, which is called single inheritance. But you can use interfaces or a combination of one class and interface(s), where interface(s) should be followed by class name in the signature.