Download MetaTrader 5
To add comments, please log in or register
Having questions to the author of an article? Discuss them on the Forum!
Pawel Wojnarowski
683
Pawel Wojnarowski 2012.04.13 23:58 

Hello MetaQuotes,

Just as in the topic - how can I declare a pure virtual function in MQL5? I would like to use this mechanism to create interfaces or implement some design patterns. Normally in C++ I would write:

virtual void Foo() = 0;

But the MQL5 compiler doesn't accept it. Should I just write:

virtual void Foo();

??

MetaQuotes Software Corp.
Moderator
178119
MetaQuotes Software Corp. 2012.04.14 00:04  

Try

class CMyClass
  {
public:
                     CMyClass(void) { }
                    ~CMyClass(void) { }

   virtual void      Foo() { }
  };

Pawel Wojnarowski
683
Pawel Wojnarowski 2012.04.14 00:28  
Thanks - however this works only for void. What about other types, e.g. bool or int? I could always try to just return some value, but then it isn't really a pure virtual function.
Pawel Wojnarowski
683
Pawel Wojnarowski 2012.04.17 12:43  
MetaQuotes - any comment on this?
Slawa
Moderator
6739
Slawa 2012.04.17 15:51  
Enigma71fx:
MetaQuotes - any comment on this?

What is the problem?

class CMyClass
  {
public:
                     CMyClass(void) { }
                    ~CMyClass(void) { }

   virtual void      Foo()  { }
   virtual bool      Foo1() { return(false); }
   virtual int       Foo2() { return(0); }
  };
Slawa
Moderator
6739
Slawa 2012.04.17 15:52  
Enigma71fx:
Thanks - however this works only for void. What about other types, e.g. bool or int? I could always try to just return some value, but then it isn't really a pure virtual function.
There are no pure virtual functions in the MQL5
Pawel Wojnarowski
683
Pawel Wojnarowski 2012.04.17 19:57  
stringo:
There are no pure virtual functions in the MQL5
OK stringo, thanks for confirmation.
bucket
38
bucket 2016.02.29 12:48  

Old thread, but I don't like to open a new thread for a topic without solution.

Funny that the MQL4 documentation explains pure virtual functions and has samples for pure virtual functions.

Alain Verleyen
Moderator
29413
Alain Verleyen 2016.02.29 17:54  
bucket:

Old thread, but I don't like to open a new thread for a topic without solution.

Funny that the MQL4 documentation explains pure virtual functions and has samples for pure virtual functions.

You have misread then.
/
To add comments, please log in or register