no way to code interfaces ?

 

Hello,


for some reasons I like to work with an interface. but my mt4 don't know the word (?)

Same code in the documentation (https://docs.mql4.com/basis/types/classes):

//--- Basic interface for describing animals
interface IAnimal
  {
//--- The methods of the interface have public access by default
   void Sound();  // The sound produced by the animal
  };

My compiler (MT4 build 1080) tells me:

"'interface' - declaration without type" and the word in code stay black.


Thanks a lot for any help - What went wrong ?

Structures, Classes and Interfaces - Data Types - Language Basics - MQL4 Reference
Structures, Classes and Interfaces - Data Types - Language Basics - MQL4 Reference
  • docs.mql4.com
Structures, Classes and Interfaces - Data Types - Language Basics - MQL4 Reference
 
Abejorro:

Hello,


for some reasons I like to work with an interface. but my mt4 don't know the word (?)

Same code in the documentation (https://docs.mql4.com/basis/types/classes):

My compiler (MT4 build 1080) tells me:

"'interface' - declaration without type" and the word in code stay black.


Thanks a lot for any help - What went wrong ?


It compiles. However I have not a faintest idea why you would use it, when you cannot implement the interface in a class in MQL.

 
Ex Ovo Omnia:


It compiles. However I have not a faintest idea why you would use it, when you cannot implement the interface in a class in MQL.

Confusing. Again: My compiler ends with the error notice "'interface' - declaration without type" in the very first line "interface IAnimal"

So there is no way to implement it in a class later.

 

Following code compiles and works for me in build 1090:


#property strict

interface IAnimal
  {
   void Sound();  // The sound produced by the animal
  };

class CCat : public IAnimal
  {
public:
                     CCat(void){};
                    ~CCat(void){};
   void              Sound(){Print("Meow");}
   void              Purr(){Print("Purrrr");}
  };

class CDog : public IAnimal
  {
public:
                     CDog(void){};
                    ~CDog(void){};
   void              Sound(){Print("Bark");}
   void              Fetch(){Print("Fetch");};
  };

CDog *dog;
CCat *cat;

int OnInit()
  {
//---
   dog = new CDog();
   cat = new CCat();
   CallAnimal(dog);
   CallAnimal(cat);
//---
   return(INIT_SUCCEEDED);
  }
  
void CallAnimal(IAnimal *animal)
{
   animal.Sound();
   
   if(dynamic_cast<CDog *>(animal) != NULL)
      (dynamic_cast<CDog *> (animal)).Fetch();

   if(dynamic_cast<CCat *>(animal) != NULL)
      (dynamic_cast<CCat *> (animal)).Purr();      

}

  
void OnDeinit(const int reason)
  {
   delete dog;
   delete cat;
  }

void OnTick()
  {
  }


I think it worked in 1080 also.

Interfaces work, and you can implement them similarly as class inheritance.

The problem I have with them is that there is no way to mix interfaces and class inheritance and I could not find a way to create a class that is derived from CObject and implements some interface.

 

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Бета версия редактора для разработчиков

Ilyas, 2016.08.15 11:39

Бета билд редактора 1381, пока только 32 битная версия.

  1. Поддерживается указатель void *
  2. Добавлены интерфейсы (interface), множественное наследование пока не поддерживается.
  3. Добавлена поддержка оператора [ ] для строк - получение символа, в случае выхода за пределы строки возвращается 0 и взводится ошибка 5041 - ERR_MQL_STRINGPOS_OUTOFRANGE

2. Added interfaces (interface), multiple inheritance is not yet supported.

"Not yet supported" so it could probably be supported one day.

 
Drazen Penic:
...

I think it worked in 1080 also.

Interfaces work, and you can implement them similarly as class inheritance.

Apologies for my late feedback, the net was gone.

And thanks for your code. I have tried with it and with only a few lines, does not compile on my system. (still the codeword 'interface')

However, I have seen that terminal.exe has been updated properly, but metaeditor.exe the version 5.00, build 1241 from 22.12.2015 remained.

Is this the latest for MT4 ? Or is there an offline installer only for the editor to force an update ?

 

"Bark" describes the action of making the sound. "Woof" might work better as a sound (printed silently on your terminal of course) :)

 
Abejorro: I have seen that terminal.exe has been updated properly, but metaeditor.exe the version 5.00, build 1241 from 22.12.2015 remained.
I have MT4 1090 (May 19) and editor 1601 (same date)
 
whroeder1:
I have MT4 1090 (May 19) and editor 1601 (same date)

Yes that was the reason. My virus scanner was sure it has been malware in each metaeditor.exe. Once I told him to ignore his idea. He has ignored my command only and denied access silently.

The update now has also eliminated a few other mysteries of the past. Funny.

Problem solved, now I can compile an interface. Thanks to all !

Reason: