
11 Dec
2006
11 Dec
'06
4:12 p.m.
On 12/11/06, Johan RĂ¥de <rade@maths.lth.se> wrote:
I have singleton class X. The instance of X is constructed the first time it is used, and is destroyed during the static destruction phase at app termination.
X::X() reads data from a ptree X::~X() writes data to a ptree
My app crashes in X::~X().
The reason is that ptree uses static variables.
Static variables are destroyed in reverse order of the completion of their constructors. Therefore, if you make sure to call any ptree functions used by ~X() in X(), this will make sure that the static variables needed by ~X() are created before construction of X is complete. That gives you the guarantee that X will be destroyed before any of the static vars it depends on. -Jason