Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#include <iostream> using namespace std; extern int i; int main() { i=10; cout<<"the value of i is"<<i<<endl; }
'extern' 告诉编译器 i 是在另一个编译单元中定义的。它不会为它创建存储,而是在链接时查找它,当您收到错误时。因此,要么链接到我定义的模块,要么删除“extern”限定符。