extern int globalVal;
extern int globalVal;
int main(int argc, char* argv[])
{
globalVal = 10;
return 0;
}
g++ -o test test.cc -c编译成目标文件后没有提示错误,但是如果将第二个globalVal声明改成double类型会有‘globalVal’ has a previous declaration as ‘int globalVal’ extern int globalVal;的错误。说明可以重复声明全局变量,但是变量类型要一致。