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);
}
};
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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...
Who can help me with this one?
Thanks!!