Click here to Skip to main content
15,888,454 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: delete in ctor ! Pin
toxcct2-Jun-06 2:19
toxcct2-Jun-06 2:19 
AnswerRe: delete in ctor ! Pin
Ștefan-Mihai MOGA2-Jun-06 2:21
professionalȘtefan-Mihai MOGA2-Jun-06 2:21 
GeneralRe: delete in ctor ! Pin
vikramlinux2-Jun-06 2:26
vikramlinux2-Jun-06 2:26 
AnswerRe: delete in ctor ! [modified] Pin
Chris Losinger2-Jun-06 2:23
professionalChris Losinger2-Jun-06 2:23 
NewsRe: delete in ctor ! [modified] Pin
Roland Pibinger2-Jun-06 4:06
Roland Pibinger2-Jun-06 4:06 
GeneralRe: delete in ctor ! Pin
Chris Losinger2-Jun-06 4:43
professionalChris Losinger2-Jun-06 4:43 
GeneralRe: delete in ctor ! Pin
Roger Stoltz2-Jun-06 5:00
Roger Stoltz2-Jun-06 5:00 
GeneralRe: delete in ctor ! Pin
Chris Losinger2-Jun-06 5:08
professionalChris Losinger2-Jun-06 5:08 
Roger Stoltz wrote:
but it will change the behaviour of the new operator which may return a pointer to the deleted object instead of NULL.


yes, as i noted in my first reply.

it's not good programming practice in general, and i can't think of a single situation where this is the best solution. but, as written, (as an academic question), it appears safe.

i've spent a bit of time this AM looking over the web for someone who can definitively show that it (as written in the OP) isn't safe - haven't found one yet. a lot of people have asked this question, and the discussions all agree that it's safe as long as you pay attention to things like virtual dtors, derived classes, no stack allocation of the object, don't trust the return from new, etc..


Cleek | Image Toolkits | Thumbnail maker

GeneralRe: delete in ctor ! Pin
Roger Stoltz2-Jun-06 5:42
Roger Stoltz2-Jun-06 5:42 
GeneralRe: delete in ctor ! Pin
Chris Losinger2-Jun-06 5:48
professionalChris Losinger2-Jun-06 5:48 
GeneralRe: delete in ctor ! Pin
Roger Stoltz2-Jun-06 6:16
Roger Stoltz2-Jun-06 6:16 
GeneralRe: delete in ctor ! Pin
Nemanja Trifunovic2-Jun-06 5:05
Nemanja Trifunovic2-Jun-06 5:05 
AnswerRe: delete in ctor ! Pin
BadKarma2-Jun-06 3:15
BadKarma2-Jun-06 3:15 
GeneralRe: delete in ctor ! Pin
toxcct2-Jun-06 3:35
toxcct2-Jun-06 3:35 
GeneralRe: delete in ctor ! Pin
Zac Howland2-Jun-06 3:47
Zac Howland2-Jun-06 3:47 
GeneralRe: delete in ctor ! Pin
Roger Stoltz2-Jun-06 4:23
Roger Stoltz2-Jun-06 4:23 
GeneralRe: delete in ctor ! Pin
BadKarma2-Jun-06 4:32
BadKarma2-Jun-06 4:32 
GeneralRe: delete in ctor ! Pin
Roger Stoltz2-Jun-06 4:38
Roger Stoltz2-Jun-06 4:38 
GeneralRe: delete in ctor ! Pin
Zac Howland2-Jun-06 5:04
Zac Howland2-Jun-06 5:04 
JokeRe: delete in ctor ! Pin
BadKarma2-Jun-06 5:13
BadKarma2-Jun-06 5:13 
QuestionMigrating from VC6 to VS2005 [modified] Pin
Obliterator2-Jun-06 1:36
Obliterator2-Jun-06 1:36 
AnswerRe: Migrating from VC6 to VS2005 [modified] Pin
Chris Losinger2-Jun-06 1:58
professionalChris Losinger2-Jun-06 1:58 
GeneralRe: Migrating from VC6 to VS2005 [modified] Pin
Obliterator2-Jun-06 2:17
Obliterator2-Jun-06 2:17 
AnswerRe: Migrating from VC6 to VS2005 Pin
Michael Dunn2-Jun-06 7:46
sitebuilderMichael Dunn2-Jun-06 7:46 
GeneralRe: Migrating from VC6 to VS2005 Pin
Obliterator9-Jun-06 2:33
Obliterator9-Jun-06 2:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.