In this question I asked why
//foo.h
namespace foo{
int bar;
}
gave me a linker error when I include foo.h
in multiple files. Turns out I need extern int bar;
to prevent the error. Why do I need extern
? I don't want to type extern
before every variable in every namespace that I want access to in multiple translation units. Why doesn't int bar;
do what I expected it to? Why does the C++ Standards Committee insist on making me type extern
everywhere?