2.4-2

    技术2025-06-19  6

    first_head.h -------------------------------- #include<iostream> using namespace std; int a=10;//非const变量默认为extern //const int a=10;//error:在全局作用域声明的const变量是定义该对象的文件的局部变量                    此文件只存在于那个文件中,不能被其他文件访问 extern const int b=10;//指定const变量为extern,就可以在整个程序中访问const对象 first.cpp -------------------------------- int main() {  extern int a;  cout<<a<<endl; //非const变量定义在一个文件中,可在另一个文件中使用这个变量  cout<<b<<endl;   system("pause"); }

    最新回复(0)