c++ destroy an object on stack frame -
i try understand happen when object destroy on stack. here sample code:
#include <stdio.h> struct b { ~b() {puts("bbbb");} }; int main() { b b; b.~b(); }
output
bbbb bbbb
based on output, can tell object destroy twice.one ~b(), 1 after "}". how , why can object destroy twice?
update: after review replies, think destructor doesnt destroy object. there way destroy object before reach out of scope "}". thanks
you not supposed invoke destructor hand. what's happening invoking destructor , when object gets popped off stack destructor called again automatically compiler.
Comments
Post a Comment