object - Why prohibit static allocation in c++? -
what point making constructor of class private , having getinstance method returns new instance? when want allow dynamic object creation , why? have seen examples of , don't understand why.
this commonly done when class instances manage own lifetime, e.g. subscribe event comes asynchronously. if instance destroyed before event arrives, event dispatcher use wild pointer , cause undefined behavior.
Comments
Post a Comment