Basicly I need to know how to refer to declared external static variables (GlobalMirror, GlobalMirror2 etc.) inside the class 'Initializer' and initialize them. The following code doesnt work (compiler doesnt see my 'extern' declarations inside the class Initializer):

#include "Mirror.h"
#include <iostream>

extern Mirror GlobalMirror;
extern Mirror GlobalMirror2;
extern Mirror GlobalMirror3;
extern Mirror GlobalMirror4;
extern Mirror GlobalMirror5;

class Initializer {
  static int initCount;
  Initializer() {
    std::cout << "Initializer()" << std::endl;
    // Initialize first time only
    if(initCount++ == 0) {
        std::cout << "performing initialization"
                << std::endl;
        //Initialization in expected and PREDICTABLE order:
       //ALL 5 FOLLOWING LINES ARE ERRORS: (compiler doesnt 'see' my 'extern' declarations which
        //are above)
        GlobalMirror2(&GlobalMirror,2);   //each object is initialized with  
        GlobalMirror3(&GlobalMirror2,3); //the previous one
  ~Initializer() {
    std::cout << "~Initializer()" << std::endl;
    // Clean up last time only
    if(--initCount == 0) {
      std::cout << "performing cleanup" 
                << std::endl;
      // Any necessary cleanup here

static Initializer init;
#endif // INITIALIZER_H ///:~

Thanks in advance

>> GlobalMirror2(&GlobalMirror,2);

You can't do that after the object has been constructed. You can only do it when actually instantiating the object. You need to write an initializer method or other method that can be called to initialize those classes, something like this


Oh! thanks very much, I should had thought about it myself! But your idea is definitely what I needed. Thx!