I've been playing with some code recently and I've been curious about one thing that I'm not sure I've figured out a correct answer to. So, let's assume that I've defined the following class.
class Thing {
public:
int m_Integer = 0;
Thing() {
std::cout << "Thing constructor has been called! Address: " << this << ".\n ";
}
~Thing() noexcept {
std::cout << "Thing destructor has been called! Address: " << this << ".\n";
}
static Thing CreateInstance() {
return Thing();
}
void* GetThis() {
return this;
}
};
I've explicitly defined default ctor and dtor to see whether these were called. OK, then, I've created a handle.
void* hThing = Thing::CreateInstance().GetThis();
Logs tell me that both constructor and destructor have been called. Does this mean that I've allocated some memory on stack, which has a layout like Thing type object but the object itself is no more?