注意include .h 文件的使用

场景

(看到项目中有如下使用方式,觉得会存在弊端,占用不必要的内存,虽然结果没有问题。)

多个变量定义在一个fid.h文件,

多个cpp文件(比如100个)同时#include "fid.h"

弊端

任意一变量会在cpp文件中展开,如果fid.h被include了100次,任一fid.h中的变量将在可执行文件中定义100次,
之所以链接不会出错重复定义,是因为变量被const修饰后,变为内链接。

</pre>fid.h<pre name="code" class="cpp">#ifndef _FID_H_
#define _FID_H_

//----------------------  Account  -----------------------------
const int FID_ACCOUNT_BASE                    = 10000;
const int FID_ACCOUNT_ID                      = FID_ACCOUNT_BASE + 0;     
const int FID_ACCOUNT_NAME                    = FID_ACCOUNT_BASE + 1;     
const int FID_ACCOUNT_PASSWORD                = FID_ACCOUNT_BASE + 2;     
const int FID_ACCOUNT_COMPANY_ID              = FID_ACCOUNT_BASE + 3;     
const int FID_ACCOUNT_TOKEN                   = FID_ACCOUNT_BASE + 4;     
const int FID_ACCOUNT_DEPARTMENT              = FID_ACCOUNT_BASE + 5;     
const int FID_ACCOUNT_COMPANY_NAME            = FID_ACCOUNT_BASE + 6;     
const int FID_ACCOUNT_ROLE                    = FID_ACCOUNT_BASE + 7;     
const int FID_ACCOUNT_PERMISSION              = FID_ACCOUNT_BASE + 8;     
const int FID_ACCOUNT_CODE					   = FID_ACCOUNT_BASE + 9;     
const int FID_ACCOUNT_TELEPHONE               = FID_ACCOUNT_BASE + 10;    
const int FID_ACCOUNT_PHONE		           = FID_ACCOUNT_BASE + 11;    
const int FID_ACCOUNT_EMAIL				   = FID_ACCOUNT_BASE + 12;    
const int FID_ACCOUNT_RM		               = FID_ACCOUNT_BASE + 13;    
const int FID_ACCOUNT_MSN		               = FID_ACCOUNT_BASE + 14;    
const int FID_ACCOUNT_QQ		               = FID_ACCOUNT_BASE + 15;    
const int FID_ACCOUNT_ADDRESS	               = FID_ACCOUNT_BASE + 16;    
const int FID_ACCOUNT_PASSWORD_ORG            = FID_ACCOUNT_BASE + 17;    
........
#endif // _FID_H_


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值