- There is no pure in MT4. You must provide a body. I defined a macro:
* #define PURE(TN) \ * { \ * PrintFormat("Pure function call %s[%s@%i]", \ * __FUNCSIG__, __FILE__, __LINE__); \ * return TN; \ * } * ~~~~ */ #define PURE(TN) {PrintFormat("Pure function call %s[%s@%i]",__FUNCSIG__,__FILE__,__LINE__);return TN;} #define OVERRIDE // nothing
and then can write:
class CAnimal { protected: // Abstract void CAnimal(void){} // Ctor public: // Methods void Sound(void) const{ do_sound(); } private: // Methods virtual void do_sound() const PURE(); virtual string do_other() PURE(""); }; //--- Derived from an abstract class class CCat : public CAnimal { private: // Methods virtual void do_ound() const OVERRIDE{ ... };
It is abstract because you can't call the constructor, only the subclass can.
- Virtual methods should always be private, called by non-virtual members. See Virtuality I use the pattern non-virt member, virtual do_member.
- There is no pure in MT4. You must provide a body. I defined a macro:
and then can write:
It is abstract because you can't call the constructor, only the subclass can.
- Virtual methods should always be private, called by non-virtual members. See Virtuality I use the pattern non-virt member, virtual do_member.
With the protected (private) constructor you still can create a new instance from a class static method. So, it is not a pure abstract class. But it is quite satisfactory workaround for the MT4 purposes I think.
Anyway, not sure what the private virtual function is for.
Hi,
I'm using Metatrader 4 build 950.
Ovo: Anyway, not sure what the private virtual function is for.
|
|
This feature is available on beta version only (currently build 961 while connecting on Metaquotes-Demo).
Looks like build 961 has been promoted to live today
Seeing this topic, I asked Metaquotes explanation...and I got the answer

|
- There is no pure in MT4. You must provide a body. I defined a macro:
and then can write:
It is abstract because you can't call the constructor, only the subclass can.
- Virtual methods should always be private, called by non-virtual members. See Virtuality I use the pattern non-virt member, virtual do_member.

The common practice with overwriting virtual functions is declaring them as protected, not private. And if this article behind the link claims that such functions have always to be declared as private, then the author is simply wrong. Using protected allows you to avoid reduncancies, using private forces deriving classes to be coded redundant.
The article said :
The point is that virtual functions exist to allow customization; unless they also need to be invoked directly from within derived classes' code, there's no need to ever make them anything but private. But sometimes we do need to invoke the base versions of virtual functions (see the article "Virtually Yours"[5] for an example), and in that case only it makes sense to make those virtual functions protected.
That makes sense.
The article said :
That makes sense.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm using Metatrader 4 build 950.
I am trying to implement an abstract base class use pure virtual methods. After reading the documentation (https://docs.mql4.com/basis/oop/abstract_type), I thought easy - very similar to C++. But is just won't compile - not even the examples in the documentation. The example code in the documentation is as follows:
The compile spits out these two errors:
The only solution I can make works it have empty implementations in the base class.
Not a major problems but the documentation does describe otherwise.
Are pure virtual methods just not supported or have I missed something?
9047.