2008-03-20

extern

extern可以聲明變數會在其它的位置被定義,這個位置可能是在同一份文件之中,或是在其它文件之中

extern聲明someVar在其它位置被定義,如果您在使用extern時同時指定其值,則視為在該位置定義變數,結果就引發重覆定義錯誤

extern double someVar = 2000; // error, `someVar' has both `extern' and initializer

Ref: http://caterpillar.onlyfun.net/Gossip/CppGossip/Scope.html

No comments:

Post a Comment