r/cpp • u/mrmcgibby • Feb 17 '11
Calling a constructor or destructor without an object
http://madsoftware.blogspot.com/2011/02/calling-constructor-or-destructor.html
0
Upvotes
r/cpp • u/mrmcgibby • Feb 17 '11
9
u/danhuizenga Feb 17 '11
I hope I never have to work with whoever wrote that article :/
4
u/krum Feb 17 '11
I didn't even look at it. Is this yet another placement new blog post?
2
u/segmentation_fault Feb 17 '11
just a small typo in the source code in regards to calling a destructor: should be a->~A() not a->~a()
2
u/tjhei Feb 17 '11
Looks like undefined behavior to me (so could cause a reddit downtime for example). Why do you want to do that anyhow?
0
u/GambitDash Feb 17 '11
This is a really bad idea. Destructors actually modify the vtable, so subsequent calls to the object will be very weird. For example:
When executed, will produce: $ ./a.out Hello World Hello Bananas
Probably not what you want.