c和c++对重复声明和定义的处理不同
2019-07-15 本文已影响0人
小胖_20c7
static int age;
static int age = 10;
上面代码,在c中可以编译成功,但是在c++中,属于重复定义
a.cpp:14:12: error: redefinition of ‘int age’
static int age = 10;
^
a.cpp:13:12: error: ‘int age’ previously declared here
static int age;
^