some butthole asked me an interview question:
can you delete "this" pointer in a member function of a class, like this:
class C {
public:
void foo() { delete this; }
};
my answer was... undefined behavior, maybe? object kills itself and frees
it's own memory, not a good thing in my opinion.
the guy tried to convince me that it's a common practice to "reload the
object", and that this delete would not actually free memory, only call
destructor(s).
now, i know C++ pretty darn well, but I'm not the all mighty guru... yet.
so, am I stupid, or was he full of shit?
Thanx
can you delete "this" pointer in a member function of a class, like this:
class C {
public:
void foo() { delete this; }
};
my answer was... undefined behavior, maybe? object kills itself and frees
it's own memory, not a good thing in my opinion.
the guy tried to convince me that it's a common practice to "reload the
object", and that this delete would not actually free memory, only call
destructor(s).
now, i know C++ pretty darn well, but I'm not the all mighty guru... yet.
so, am I stupid, or was he full of shit?
Thanx
Comment