我写了以下代码
头文件
int i = 0;
样本.cpp
#include <stdio.h>
#include "head.h"
extern int i;
i = 20;
int main() {
printf("%d \n",i);
return 0;
}
当我编译 sample.cpp 时,编译器抛出以下错误:
sample.c:5:1: warning: data definition has no type or storage class [enabled by default]
sample.c:5:1: error: redefinition of ‘i’
head.h:1:5: note: previous definition of ‘i’ was here