I am trying to get the correct setting:
This application (with several source files, compilation units) has global variables of the type class Adefined in many compilation units. They must be “managed” by the new in order to introduce class B(where only one instance should exist) in the sense that when they are created they are “registered” themselves in an instance of class B and, when destroyed, are “signed”.
Setting up work for designers to work is pretty straightforward. Can be used:
types.h:
class B {
static B& Instance() {
static B singleton;
return singleton;
}
void registerA( const A& a ) {
}
};
class A {
A() { B::Instance().registerA( this ); }
};
How to get destructors correctly? Using:
class A {
A() { B::Instance().registerA( this ); }
~A() { B::Instance().signoffA( this ); }
};
B A.
A B.
class A :
file1.cc
#include "types.h"
namespace C {
A a;
}
file2.cc
#include "types.h"
namespace C {
A b;
}
, Boost smart pointers. , , , .
, : .