标签:included include 技术分享 log src class 头文件 技术 类型
#ifndef MY_H_INCLUDED #define MY_H_INCLUDED extern int a ; extern const int b; #endif // MY_H_INCLUDED
#include "my.h" int a = 100 ; extern const int b = 200 ;
#include <iostream> #include "my.h" int main() { std::cout<<a<<std::endl; std::cout<<b<<std::endl; return 0; }
结论:对于const类型常量,需要申明和定义都加上extern。而,普通全局变量,只需要在头文件申明时加extern
标签:included include 技术分享 log src class 头文件 技术 类型
原文地址:http://www.cnblogs.com/guozhikai/p/6104911.html