class with parent class and implement an interface

 

Hi,

I have a class hierarchy and want some of those objects to also implement an interface something like below. Is this possible in MQL5?

the example below doesnt work obviously. Is there some way to get a class to have a parent class and implement an interface?

interface Foo
{

    void doSomething(void);
};
class Base
{
...
};
class Inherited : public Base, Foo
{
...
};
void Inherited::doSomething(void)
{
        return;
}
 
Chris McDonald:

I have a class hierarchy and want some of those objects to also implement an interface something like below. Is this possible in MQL5?

the example below doesnt work obviously. Is there some way to get a class to have a parent class and implement an interface?

No multiple inheritance in MQL5 (so far) - try other workaround approaches, for example, composition; or derive Base from the interface, or probably play with templates.

class Base2
{
public:
  template<typename T>
  void doSomething(void) { }
};
 
Stanislav Korotky #:

No multiple inheritance in MQL5 (so far) - try other workaround approaches, for example, composition; or derive Base from the interface, or probably play with templates.

Many thanks stanislav for confirmation of that - will do as you suggest.

c