R
Raider
Are global objects always constructed in order of they declaration?
I use one global in the constructor of another one and I want to be sure
it works the same with any compiler. The code looks like this:
#include <iostream>
class Class1
{
public:
Class1() { std::cout << "Class1()" << std::endl; }
void Use() { std::cout << "Class1::Use()" << std::endl; }
};
Class1 Global1;
class Class2
{
public:
Class2() { Global1.Use(); }
};
Class2 Global2;
int main(int argc, char* argv[])
{
return 0;
}
I use one global in the constructor of another one and I want to be sure
it works the same with any compiler. The code looks like this:
#include <iostream>
class Class1
{
public:
Class1() { std::cout << "Class1()" << std::endl; }
void Use() { std::cout << "Class1::Use()" << std::endl; }
};
Class1 Global1;
class Class2
{
public:
Class2() { Global1.Use(); }
};
Class2 Global2;
int main(int argc, char* argv[])
{
return 0;
}