Re: [Dev-C++] "delete this" in the class member
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Obi <ob...@ch...> - 2004-01-31 04:51:31
|
At 00:18 29/01/2004 +0000, Miguel Ram=EDrez J=E1vega wrote: >On Wed, 2004-01-28 at 09:04, Oleksandr Yermolenko wrote: > > Hi all, > > Little question about delete operator. > > Can i fall into trouble when making a call "delete this" in the > > class member function ? > > > >What do you mean exactly by "falling into trouble"? Obviously, the first >think one thinks at seeing that is the risk of dangling references. Any >reference to that struct instance will be invalid. And second, valgrind >prompts the following when executing the snippet of code you sent: Also you need to be sure the instance is actually new-ed. If the instance is an automatic or static variable callinf "delete this" will have undefined behaviour, probably bad. If you want to "delete this" you are recommended to have private constructors and destructor. Use a factory method to create objects. |