Download MetaTrader 5

how to declare a pure virtual function in MQL5??

To add comments, please log in or register
Pawel Wojnarowski
686
Pawel Wojnarowski  

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
183631
MetaQuotes Software Corp.  

Try

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

   virtual void      Foo() { }
  };

Pawel Wojnarowski
686
Pawel Wojnarowski  
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
686
Pawel Wojnarowski  
MetaQuotes - any comment on this?
Slava
Moderator
6924
Slava  
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); }
  };
Slava
Moderator
6924
Slava  
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
686
Pawel Wojnarowski  
stringo:
There are no pure virtual functions in the MQL5
OK stringo, thanks for confirmation.
bucket
38
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.

Alain Verleyen
Moderator
31600
Alain Verleyen  
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