Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualCornstalks

Posted 21 March 2013 - 11:12 PM

What if I used the stack instead?

Nope. First, you can't delete things on the stack. And second, even if you manually called the destructor, it's still undefined behavior. If you use the non-trivial destructor in any way before returning from the constructor, it's undefined behavior.

#1Cornstalks

Posted 21 March 2013 - 11:07 PM

 

So short, so sweet.  Isn't C++ great once you use it properly?

Sure, except for you're not using it properly (to put it bluntly). Seeing as the constructor never finishes being called, and the non-trivial destructor is called (while effectively in the constructor), you've officially invoked undefined behavior. See this StackOverflow question for some details

 

What if I used the stack instead?

Nope. First, you can't delete things on the stack. And second, even if you manually called the destructor, it's still undefined behavior. If you use the non-trivial destructor in any way before returning from the constructor, it's undefined behavior.


PARTNERS