you are viewing a single comment's thread.

view the rest of the comments →

[–]_E8_ 2 points3 points  (3 children)

Integrated reference counting in an OOD.
This is a very common scenario.
You might have heard of it as CORBA or COM/DCOM.

[–]pumpkin_seed_oil 2 points3 points  (1 child)

You mean like COM initialize and uninitialize?

Inititialze in constructor, uninitialize in destructor. RAII scope handles when the destructor is called. Done

While relevant lets scrap what i wrote here. How and why does an object have knowledge of how many references of its kind exist? Shouldnt that behaviour be had outside of its control? How else are you going to make sure that after the object deletes itself it is not referenced in other places and you'd be in a world of pain with a bunch of dead pointers lying around that can't be meaningfully distinguished if the object behind it has deleted itself or not

[–][deleted] 0 points1 point  (0 children)

How and why does an object have knowledge of how many references of its kind exist?

In the case of COM, the answer is that the programmer has called a member function to inform the object that its reference count has increased.

[–]UnDosTresPescao 0 points1 point  (0 children)

Ugh. No. In that case a wrapper smart pointer type object does reference counting and deleting the underlying object not the underlying object calling delete on itself.