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?
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?
class CCC
{
public:
datetime start; //Сохраняем время создания объекта класса ССС
CCC(void) : start(TimeCurrent()) {}; //Функция TimeCurrent() указана без символа "точка с запятой"
~CCC(void) {};
}
voidOnTick()
{
CCC ccc;
}
That's because the ; in line 7 is missing, while lines 6 and 5 don't need it.
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.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Doesn't seem to compile.
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 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.
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
That's because the ; in line 7 is missing, while lines 6 and 5 don't need it.
You're thinking in the right direction.
This code does not compile
That's because the ; in line 7 is missing, while lines 6 and 5 don't need it.
Doesn't seem to compile.
It compiles (well, I'm not picky about semicolons ;-) ).
So the questioner has exactly the problem with them.
In general, it's such trifles...
This code does not compile
That's because the ; in line 7 is missing, while lines 6 and 5 don't need it.