Errors, bugs, questions - page 1182

 
Zeleniy:

Optimisation is not working.

2014.08.05 19:34:42 Tester no optimized parameter selected, please check input(s) to be optimized and set carefully start, step and stop values

Translation did not give anything.

What do you mean "nothing"? The translation should have given you something, like that you must select at least one parameter for optimization and make sure that the start, end and step values are correct.
 
marketeer:
What do you mean, "nothing"? The translation should have given me something, like that I should select at least one parameter for optimisation and make sure that the start, end and step of the test are correct.
It's so weird, I don't understand anything, maybe I'm just tired, I'm still struggling with errors for the second day. Thank you, I will rely on your words.
 

I faced this problem: I need to compare two objects of the same class with each other and decided to overload operator == for convenience. It turned out that if the objects are dynamic, my operator is not executed, and instead of the objects themselves their pointers are compared. Well, it makes sense in principle, the operation of jumping to the object by its pointer is required: *a == *b. But in MQL this possibility had been forgotten. We have to add.

class T {   int x;

public:

T (int value) { x=value; }   bool operator==(T& other) { Print("compare1");  return x==other.x; }   bool operator==(T* other) { Print("compare2");  return x==other.x; } }; //------------------ void OnStart() {   T* a= new T(10);   T* b= new T(10);      Alert(a==b);      delete a;   delete b; }

 

Although I've just thought, the fact that we're comparing pointers instead of objects is fundamentally wrong, considering the specifics of the language. After all, MQL is a managed language, and the very concept of "object" is used here regardless of how the object is stored and how it's accessed. Members and methods are in any case accessed by a dot. Correspondingly, the comparison operator should work the same way both for statically selected objects and dynamic ones. And if you need to compare pointers, you should do itusing GetPointer().

 
meat:

Although I was just thinking, the fact that there is a comparison of pointers instead of the objects themselves is fundamentally wrong, given the specifics of the language.

There's no need to invent comparison rules in MQL that contradict C++, as long as you can do it by other means. If you have pointers and you need to compare objects - use a compare function.
bool Compare(const T& t1, const T& t2 ) { return ( t1 == t2 ); }

Alert( Compare( a, b ));
It's one thing to allow a record of the form (*a == *b) and quite another thing to give a different meaning to the record (a == b)
 

When testing the Expert Advisor, it generates an error

invalid takeprofit for OrderSend function

OrderSend error 4107

How can I fix it without going into the code?

 
A100:
There's no need to invent comparison rules in MQL that contradict C++, as long as other means can be used. If you have pointers and you need to compare objects, use a comparison function It's one thing to suggest allowing an entry of the (*a == *b) kind, and quite another thing to give a different meaning to the (a == b) entry

Well, I'm explaining that MQL rules contradict C++ as it is. Referring to an object by a pointer here is done with a dot, while it should be done with ->, if we follow C++ rules.

I.e. "pointer" and "object" are two absolutely different notions in C++, that's why the syntax is different. Everything is strict. But here everything is mixed up. It looks as if we address properties and methods of a pointer. I am not saying that it is bad, it is more convenient to OOP, it is done in C# for example. But then everything else must be implemented in the same way. There must be a single concept. Otherwise contradictions and confusion occur: in some cases we use a pointer the same way as the object itself, and in other cases the pointer suddenly comes to life.

Proceeding to the practical side of all this, I have already faced a problem: my code was using static objects. Then I decided to replace some of them with dynamic ones. As a result, comparison and assignment operations started working quite differently. And this problem was difficult to detect because the program continues to compile and work normally but not in the way it should.

 

I have some class in my code that contains some object:

CClass
{
  ...
  CObj  Object; 
  ...
};

The CObj class is declared before it.

When trying to compile I get an error: 'Object' - cannot be unset

What does this error mean and what is its cause? I don't remember encountering this error before. The CObj class has a constructor and destructor.

I tried to declare Object simply as a variable - everything is OK. But it won't do that when it is part of a class.

 
So, can someone explain what this error ("- cannot be unset") is? When does it occur?
 
meat:
So, can someone explain what this error ("- cannot be unset") is? When does it occur?
The ZeroMemory function cannot be used for this object