//const1.cpp #include <iostream> usingnamespace std; constint a=1; void funcA() ...{ cout<<"cout int A in file const2.cpp have value of "<<a<<endl; }
// const2.cpp #include <iostream> usingnamespace std; constint a=2; externvoid funcA(); void funcB() ...{ cout<<"cout int A in file const2.cpp have value of "<<a<<endl; } int main() ...{ funcA(); funcB(); }
编译并执行
g++ const1.cpp const2.cpp ./a.out
输出结果
cout int A in file const2.cpp have value of 1 cout int A in file const2.cpp have value of 2