c++ - Why is "static" needed for a global const char but not for a bool? -


shared header.

i can this:

const bool kactivateplayground=false;

works fine when included among multiple files.

i cannot this:

const char * kactiveplayground = "kiddiepool";

results in error: duplicate symbols.

but works:

static const char * kactiveplayground = "kiddiepool";

why static needed const char * not const bool ? additionally, thought static not necessary since const static implicity?

in c++, const variables default have static linkage, while non-const variables have external linkage.

the reason multiple definitions error that

const char * kactiveplayground = "kiddiepool"; 

creates variable external linkage.

hey wait, didn't const variables default static linkage? yes did. kactiveplayground not const. non-const pointer const char.

this work expect:

const char * const kactiveplayground = "kiddiepool"; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -