You have to call that in another function. If it can be called more than once, you can call it in your B constructor, so every time a B instance is created it is called. This only makes sense if it is basically a no-op when it is called after the first time. You can write a separate function (or static member function of B) and call this once at the start of your program (or somewhere else). You can also create another class that calls that function in the constructor, then make a static member of that class inside B:
Code:
class B
{
static A instance_of_A;
class A_Initializer
{
public:
A_Initializer() { B::instance_of_A.initialize(); }
};
static A_Initializer initializer;
};
// in cpp file:
A B::instance_of_A;
B::A_Initializer B::initializer;