Liste des Groupes | Revenir à cl c |
On 28/08/2024 10:45, Bonita Montero wrote:This sample (in cake) shows how I can move from const objects and how I don't need the concept of destructor and how it is safer than C++ RAII (because the fixes don't depend on programmer reading guidelines)Am 28.08.2024 um 15:35 schrieb Thiago Adams:You have to deallocate only if the ownership still with the same object.
>In C you learn how to write less code.>
You do th same in C, but manually.
>RAII, destructor, constructor is a bad idea, but I don't know if it is a good place to talk about it. I also don't know if I will be able to convince you.>
If you have a allocated resource you've to deallocate it at the end of
the scope. In C you do that error-prone with goto-orgies like in the
Linux-kernel. In C++ there's no goto necessary and the resulting code
is the same.
This is not the case when the object is moved.
To create view object you need a new object because destructor cannot be disabled.One problem of RAII and destructor we cannot disable it.>
If you've got to deallocate the memory you need the destructor.
If you move your container elsewhere and the compiler sees that
the destructor is opimized away for the non-exception code-path.
For instance
X x;
ViewX x; //no destructor here..
etc..
excuses..By the way, in C++ we cannot move const objects. This is ridiculous.>
Const-objects are there not to be modified. If you've got logical
constness you can cast away the const with const_cast and move its
contents. But casting away const is unclean mostly in C and C++.
Les messages affichés proviennent d'usenet.