新手请教个 变量赋值的问题
test1.h
程序代码:
#ifndef _TEST_H
#define _TEST_H
extern int a;
#endif
test1.cpp
程序代码:#include <iostream> #include "test1.h" int a = 1;
test.cpp
程序代码:
#include "test1.h"
#include <iostream>
using namespace::std;
a = 2; // 如果这样写会出错, does not name a type 将这行放在 main 中赋值就没有问题,这是为什么
int main() {
cout << a << endl;
}








