For example, I have 4 COM pointers, named ptr0
to ptr3
, and initialize them in the constructor as follows:
Class::Class()
{
// Real code
ptr3 = ...
ptr2 = ...
ptr0 = ...
ptr1 = ...
}
Are they automatically released in the destructor in the reverse order of their declaration, like this? Like how a class would be destructed in the reverse order of its construction.
Class::~Class()
{
// Not real code, just my assumption of what happens
ptr1->Release();
ptr0->Release();
ptr2->Release();
ptr3->Release();
}
I've been getting interested in RAII and other stuff like this now that I've had it explained to me in a way that I can clearly understand, but I want someone more qualified to make sure if my assumption of what happens in the above examples is correct or not, just so that I feel comfortable with what happens during my code and how I can control it.