I implemented a base class for reference couting. The problem now is that because the RemoveReference function is a public one and might destroy and delete the object when the reference count drops to 0 the D invariant handler will crash because it gets called always at the end of that function. Now I want this function to be public because I might need to manually add / remove references at some point. Also I want destruction in there because I don't want to copy the destruction code in every place I call RemoveReference. Is there even a way to fix this?

Ideas I had so far
1) Make the RemoveReference function private and only allow reference counting through a smart pointer 2) Make the base class a templated struct which is always the first member of the class (hacky)

Is there a way to disable invariants globally (compiler switch?). Because in release mode I don't want the invariant hander to be called especially since the class does not even use invariants.

Is there a way to disable invariants per class?
--
Kind Regards
Benjamin Thaut

Reply via email to