Download MetaTrader 5
To add comments, please log in or register
Launch agents on an idle PC. It is profitable!
Peter van den Berg
6
Peter van den Berg 2015.01.13 21:18 

Hi all,

I am pretty new to MQL4 and have a question about polymorphism in MQL4 which think will be most clear if I show some C# code of what I am trying to achieve:

class B
{
    public void X() { }
}

class C<T>
{
    protected T t;
}

class D : C<B>
{
    public void Z()
    {
        t.X();
    }
}

So, from class D, i want to be able to call the function X on member t. I know MQL4 does not have the concept of generics, but does anybody have any idea of how I can achieve something similar to the code above, but then in MQL4? The only thing I could think of is the code below, but that includes a downcast from T to B (and needs an extra private function Y), which does not seem right at all... 

class T
{
};

class B : T
{
public:
    void X() { }
};

class C
{
protected:
    T * t;
};

class D : C
{
private:
    void Y(B * t)
    {
        t.X();
    }
public:
    void Z()
    {
        Y(t);
    }
};

Who can help me with this one?

 

Thanks!! 

/
To add comments, please log in or register