PLO. Application issues - page 18

 
TheXpert:
Doesn't seem to compile.
It works :/ Try it. Of course, I've described the design schematically, but my similar one compiles fine.
 
Yedelkin:

The search doesn't work. I may be repeating myself, but the question is: can a class object destroy itself? I.e. first we get a reference of the object to itself in the class object using the reserved word this, then we apply the delete operator to the corresponding object descriptor (pointer).

Something like:

Or is it better/preferable to delete an object "externally" rather than "internally"?

I also wondered about this question. I came to the following conclusion: object can delete itself (painlessly), but it must be remembered that object data (variables) won't exist after that, so no calls to them. But imho this is a dirty way, better from outside. And if the object deletes itself, it can only be created in new.
 
220Volt:
I also wondered about this issue. The conclusion is the following: the object can delete itself (painlessly), but we must remember that after that the object data (variables) will not exist, so no calls to them. But imho this is a messy way, better outside.
Yes, I've been using it for a year now :) Very handy if the object is no longer needed. I don't understand why you consider it as a "dirty" way?
 
Yedelkin:

Maybe start by reading the documentation for the language you intend to work with, and see the definitions used for the purposes of that programming language?

Respectfully.

You are thinking in the right direction.

 

This code does not compile

class CCC
{
   public:
      datetime start;                      //Сохраняем время создания объекта класса ССС
      CCC(void) : start(TimeCurrent()) {};  //Функция TimeCurrent() указана без символа "точка с запятой"
     ~CCC(void)                      {}; 
}
  
void OnTick()
{
   CCC ccc;
}

That's because the ; in line 7 is missing, while lines 6 and 5 don't need it.

 
kazakov.v:

You're thinking in the right direction.

I gather that you don't read the language documentation very much :)
 
TheXpert:

This code does not compile

That's because the ; in line 7 is missing, while lines 6 and 5 don't need it.

I.e. the trouble will start when creating a class object? OK, thanks, I'll check it now.
Документация по MQL5: Основы языка / Операторы / Оператор создания объекта new
Документация по MQL5: Основы языка / Операторы / Оператор создания объекта new
  • www.mql5.com
Основы языка / Операторы / Оператор создания объекта new - Документация по MQL5
 
TheXpert:
Doesn't seem to compile.
It will compile (well, I'm not picky about semicolons ;-) ).
 
marketeer:
It compiles (well, I'm not picky about semicolons ;-) ).

So the questioner has exactly the problem with them.

In general, it's such trifles...

 
TheXpert:

This code does not compile

That's because the ; in line 7 is missing, while lines 6 and 5 don't need it.

Strange, everything compiles in my code even after your additional lines with OnTick(). Only after declaration of the CCC class you need to put a semicolon. As you wrote, - you need to put a semicolon in the 7th line.