Could any body offer me any reason about that?
If we do it like that, what’s the outcome? Compile error?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem is that static initialization isn’t just initialization, it is also definition. Take for example:
hacks.h :
main.cpp :
foo.cpp :
In this case, you can’t initialize
Foo::bar_in the header because it will be allocated in every file that#includes hacks.h. So there will be 2 instances ofFoo.bar_in memory – one in main.cpp, and one in foo.cpp.The solution is to allocate & initialize in just one place:
foo.cpp :