When I add this code in existing cpp with one of my class implementation
#include <iostream>
struct TestStruct{
TestStruct(int i)
{
std::cerr << i << std::endl;
x = i;
}
int x;
};
TestStruct t(8);
It prints 8 before main executed.
But when I created new empty file test.cpp and put the same code in it, nothing was printed. I checked that this cpp was compiled and linked. All cpp files compiled as static lib and then this lib with main.o linked in executable file. I use g++ 5.3 only option is -std=C++14.
Why in the second case global variable initialization are missed?