Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1097

 
Seric29:

A pointer to a function is passed as a parameter. I see no one has figured out how to do this with classes. It's also still not clear to me why a pointer to a class should be returned.

Here are interesting samples but they are not relevant to my question.

I have also seen something similar in the guide, but I have already closed these sites because my hands hurt and I have work to do.

Why should I play with such a simple task? You can simply get the needed data through a class object

I am familiar with references, pointers and function pointers, but I rarely use them in practice. And in general, I think that they are needed only for memory saving - and Expert Advisors with indicators are not games, so we can manage with common variables and class objects inthe global scope

 
Alexandr Sokolov:

Why go to such lengths with such a simple task? You can simply get the required data through a class object

I am familiar with references, pointers and pointers to functions, but I rarely use them. To my mind, they are necessary only for memory saving, the Expert Advisors with indicators are not games, therefore, we can use ordinary variables and class objects in the global scope.

I don't want to get fancy on a simple task, and of course, I modify my programs where function was called before, I write an arithmetic expression to simplify calculations or switch to a simplified overloaded function, so I want to translate the program to classes. But as you wrote above and rarely use them, and now the question is classes are there but creating pointers to functions of this class is impossible, why this kind of programming is needed, if you do one you can't do the other, it's not programming but the devil knows what.

 
Seric29:

I don't want to get fancy on a simple task, and of course I redo my programs where previously a function was called, I write an arithmetic expression to simplify calculations or switch to a simplified overloaded function, so I want to translate the program into classes. But as you wrote above and rarely use them, and now the question is classes are there but creating pointers to functions of this class is impossible, why this kind of programming is needed, if you do one you can not do the other, it is not programming but the devil knows what.

A class is a template of some object, and in order to use the functionality that is in this template - you must first create an object.

In essence, the class name acts as a data type, like int, double, string, etc., but with extended functionality. You can't declare a variable without specifying its type.

And on top of that, you can simply detach the function from the class and it can be used in the class and separately from the class without creating an object

 

Can there be any other reason why the indicator doesn't work, except that its file has been deleted from the appropriate folder? (the indicator is compiled and works in one terminal, but not in another)


 
Alexandr Sokolov:

Class is a template of some object, and in order to use functionality that is in this template - you have to create an object first.

In fact, the class name acts as a data type, like int, double, string, etc., but with extended functionality. You can't declare a variable without specifying its type.

And on top of that, you can simply detach the function from the class and it can be used in the class and separately from the class without creating an object

Unless. Well, it's just that classes are a complicated topic, and the reference book is full of examples on transfer, on creating references and pointers, I think it's possible (at least in c++ it's possible, but mql4 has nothing to do with c++), it's necessary to understand how it works. Help shows these examples they are very complicated and overloaded, instead of taking a class and showing a simple example they overloaded it with extra calculations and information and I can't understand what they mean, I closed all these links because of exhaustion and fatigue. Okay, so I'll just pull functions from the class.

 
Alexandr Sokolov:

Can there be any other reason why the indicator doesn't work, except that its file has been deleted from the appropriate folder? (the indicator is compiled and works in one terminal but not in another)


From the marketplace?

 
Alexandr Sokolov:

Can there be any other reason why the indicator doesn't work, except that its file has been deleted from the appropriate folder? (the indicator is compiled and works in one terminal, but does not work in another)


see messages in terminal and Expert Advisor logs

your screenshot shows only that this indicator has no source code

 
Alexandr Sokolov:

Can there be any other reason why the indicator doesn't work, except that its file has been deleted from the appropriate folder? (the indicator is compiled and works in one terminal, but not in another)


Maybe it needs additional libraries
 
Сергей Таболин:

From the marketplace?

No

Igor Makanu:

see messages in the terminal and Expert Advisor logs

Your screenshot shows only that this indicator has no source

Thank you

MakarFX:
Perhaps it needs additional libraries

Exactly no, I wrote it - I would know

 

Please tell me why the compiler generates a warning in the following MQL4 test script code:

#property strict

struct st_sig {
   string   sym;           // Symbol
   int      age;           // Bars ago
}; st_sig Signals[];

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {

   BubbleSort(Signals);
   
}

//+----------------------------------------------------------------------------+
void BubbleSort(st_sig &sig[]) {
  double t;
  int    i, j, n=ArraySize(sig);

  for (i=n-1; i>0; i--) {
    for (j=0; j<i; j++) {
      if (sig[j].age>sig[j+1].age) {
        t=sig[j].age;
        sig[j].age=sig[j+1].age;
        sig[j+1].age=t;       // Line#27 with warning
      }
    }
  }
}

A warning on line 27 about data type mismatch. Both variables have the same int type. Below is a screenshot of the script compilation.

If I replace line 27 with

sig[j+1].age=(int)t;

the warning doesn't show up.

What is the trick?