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;
^
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;
^
本文标题:c和c++对重复声明和定义的处理不同
本文链接:https://www.haomeiwen.com/subject/qlvnkctx.html
网友评论