Data members of a class are constructed in the order that they're declared in the class. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
template <int n>
class A{
public:
A(){
std::cout << n << std::endl;
}
};
class B{
A<42> a;
A<93> b;
A<67> c;
};
int main(){
B b;
}
The output for this program is
42
93
67
On line 10 you initialize text::address using text::addr (declared on line 14), but text::addr hasn't been constructed yet, so the memory for that future object is in an undefined state. You're basically doing this:
1 2 3
char mem[sizeof(std::string)];
//mem is uninitialized
std::string s = *(std::string *)mem;