简体   繁体   中英

Why does value assignment exclude extern keyword and declare variable?

I understand why this won't link:

extern bool g_WinGame;
...
g_WinGame=true;

But why does this compile and link?

extern bool g_WinGame=false;
...
g_WinGame=true;

I'm using MSVC 2010

[edit] all is explained HERE

extern bool g_WinGame;

is a declaration.

extern bool g_WinGame=false;

is a definition. Here extern is redundant but legal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM