|
From: Bojan N. <bo...@bn...> - 2012-02-29 23:57:36
|
Hi Luigi, I haven't fully worked this one out, but I think that it is possible to some progress on this by making the destructor of the Observer class private and then creating some helper classes (probably inheriting from shared_pointer) that are friends of Observer and define proper clean order, i.e., disconnect the Observables before starting the main destruction. This approach would enforce code correctness at compile time (because non-safe destruction of Observer objects would be a compile time error) but would obviously require changes to existing code. It should play fairly well with SWIG which is I think already aware of the implications of a private destructor. There is no less invasive way I can think of at moment -- the goal of having easy composition of objects in C++ makes it very hard to re-order destruction operations! Possibly one can do something very clever with clone()-able objects and overriding the operator new() for Observer but that would be getting really complicated.... Best, Bojan -- Bojan Nikolic || http://www.bnikolic.co.uk |