objA.Execute(); // expectation is to run Func in class A internally
objB.Execute(): // expectation is to run Func in class B internally
But when the function is called internally within constructor, derived Func in B is never called.
but in mql it Execute is calling Func in class A in both scenarios. Am i doing it wrongly or is there any other way to achieve this functionality. My main intention is to have one entry point, and multiple derived classes with specific intentions in Func methods. But its not working. Someone direct me properly here. Thanks.
Works as expected for me:
A* objA= new A(); objA.Execute(); // expectation is to run Func in class A internally
B* objB= new B(); objB.Execute(): // expectation is to run Func in class B internally
but in mql it Execute is calling Func in class A in both scenarios.
-
Play videoPlease edit your post.
For large amounts of code, attach it -
Wrong. Your code, as posted, does exactly what you expect it to do.2017.01.31 12:16:51.463 testscr AUDJPY,M1: uninit reason 0
2017.01.31 12:16:51.463 testscr AUDJPY,M1: from Class B
2017.01.31 12:16:51.463 testscr AUDJPY,M1: from Class A
2017.01.31 12:16:51.463 testscr AUDJPY,M1: initialized

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am learner and beginner in MQL. I am trying to achieve inheritance possiblity:
Below is situation where i am finding diffculties.
template <typename T>
class A
{
protected:
virtual T Func()
{
Print("from Class A");
return NULL;
}
public:
A(){Execute();}
void Execute()
{
Func();
}
};
template <typename T>
class B : public A<T>
{
public:
B(){}
protected:
T Func()
{
Print("from Class B");
return NULL;
}
};
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
A<int>* objA= new A<int>();
//objA.Execute();
B<float>* objB= new B<float>();
//objB.Execute();
delete objA;
delete objB;
}
When calling execute, i create instance.
A* objA= new A();
objA.Execute(); // expectation is to run Func in class A internally
when i create instance of B
B* objB= new B();
objB.Execute(): // expectation is to run Func in class B internally
But when the function is called internally within constructor, derived Func in B is never called.
but in mql it Execute is calling Func in class A in both scenarios. Am i doing it wrongly or is there any other way to achieve this functionality. My main intention is to have one entry point, and multiple derived classes with specific intentions in Func methods. But its not working. Someone direct me properly here. Thanks.