struct foo{
int bar1 = 5;
const static int bar2 = 6;
};
Sharing foo using a header file among multiple translation units doesn't cause a link error for bar1 and bar2, why is that?
To my knowledge, bar1 doesn't even exist until an instance of foo is created and each instance of bar1 will have unique symbol, so no link errors can happen. bar2 is not even a definition, it's a declaration with initializer and needs to be initialized with const int foo::bar2; in only one file so again no link errors can happen.
Referring to this answer: https://stackoverflow.com/a/11301299
Is my understanding correct?