解析“extern”
1、 声明外部变量
//A.cpp int i;
void main() { } |
//B.cpp int i; |
Linking... B.obj : error LNK2005: "int i" (?i@@3HA) already defined in A.obj Debug/A.exe : fatal error LNK1169: one or more multiply defined symbols found Error executing link.exe.
A.exe - 2 error(s), 0 warning(s) |
//A.cpp
void main() { i = 100; //试图使用B中定义的全局变量 } |
//B.cpp int i; |
Compiling... A.cpp C:/Documents and Settings/wangjian/桌面/try extern/A.cpp(5) : error C2065: 'i' : undeclared identifier Error executing cl.exe.
A.obj - 1 error(s), 0 warning(s) |
//A.cpp
extern int i; void main() { i = 100; //试图使用B中定义的全局变量 } |
//B.cpp int i; |