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):
#ifndef INITIALIZER_H
#define INITIALIZER_H
#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;
public:
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)
GlobalMirror(1);
GlobalMirror2(&GlobalMirror,2); //each object is initialized with
GlobalMirror3(&GlobalMirror2,3); //the previous one
GlobalMirror4(&GlobalMirror3,4);
GlobalMirror5(&GlobalMirror4,5);
}
}
~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
Ed