Errors, bugs, questions - page 1785
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I know what the destructor is for. It's not clear to me why the word virtual should be written before its definition.
I need it for code compatibility with C++, because destructors are different there
I know what the destructor is used for. I don't understand why we have to add the word virtual before its definition.
Virtual functions and destructor >>>
The basic rule: if you have at least one virtual function in your class, the destructor should also be virtual. Remember that the destructor is not virtual by default, so you should declare it explicitly. If you don't do this, you are almost certain to have memory leaks in your program. Again it doesn't take much intelligence to understand why. Let's look at several examples.
Got it, thanks. Do you port to MQL5 a lot? - Is that why the examples are so specific?
Virtual functions and destructor >>>
{
A * pA = new B;
delete pA;
return EXIT_SUCCESS;
}
This time the object is constructed as it should be, but when it is destroyed, a memory leak occurs, because the destructor of the derived class is not called.
The reason is that deletion is performed through a pointer to a base class and the compiler uses early binding to call the destructor. The destructor of the base class cannot call the destructor of the derived class because it does not know anything about it. As a result, some of the memory allocated for the derived class is irretrievably lost.To avoid this, the destructor in the base class must be declared as virtual.
I don't understand architecturally why, by making the base destructor virtual, information about the derived destructor appears.
The way I understand it now is that when the base is virtual, by defining a derivative destructor we make a replacement for the derivative destructor instead of the base destructor. But then the base destructor should not be called in this example.
Obviously, I don't understand how this works. I have never had problems with virtual functions in MQL5. I like a lot of OOP because of them. I thought I understood it all. Now I have a complete dilemma. Please explain it to me on your own terms.
Portraying little. Specific only at first glance. Some "experts" wrote here that EVERYTHING more than 3 derivative classes is harmful. I often have only 3-4 base classes to properly initialize and only then the real derivatives start
But then the base destructor should not be called in this example.
It is called by the derived destructor implicitly. That's actually what makes it different from simple virtual functions.
SymbolInfoTick() error returning irrelevant data - tick overshoot. Build 1525 x64. Test from indicator, did not test on Expert Advisor:
Real, Opening, Access Server V. Sadness! Pay attention to the problem, please. And also to the problem in application#1598238 (starting from page 10, post of2017.01.26 09:43).
Dear developers, let's fix the ticks! Code provided, here it is - the problem, no need to look for anything, just react and fix it!