假如存在A.h/A.cpp和B.cpp。如果在A.cpp中定义了int h,那么想在B.cpp中引用h的话,需要在A.h中extern int h,然后在B.cpp中include "A.h",而不能直接在B.cpp中extern int h.
C++中使用extern引用其它文件中定义的变量
最新推荐文章于 2024-01-25 09:06:59 发布
假如存在A.h/A.cpp和B.cpp。如果在A.cpp中定义了int h,那么想在B.cpp中引用h的话,需要在A.h中extern int h,然后在B.cpp中include "A.h",而不能直接在B.cpp中extern int h.