C++命名规范总结

本身命名规范并没有统一的标准,但是还是会有一些类似于 i 作为迭代次数,T 作为模板这样不成文又广为受用规则,尽可能多的熟悉这些规则,在阅读开源项目时能获得得到更多的信息,看的更明白一些。

参考文档:
Google 开源项目风格指南 (中文版)
Windows Coding Conventions

变量命名

DrivePose_t* pPose;//DriverPose_t的_t结尾表示type,说明DriverPose_t是个类型
				   //pPose的p开头表示pointer,说明pPose是个指针
int g_Mode;//g_开头表示global,说明g_Mode全局变量
int m_Socket;//m_表示member,成员变量
const char* k_Settings_RenderWidth;//k_表示const或constexpr,常量
bool bSwitch;//b表示bool

// 涉及windows编程会碰到很多h,lp,w开头的变量
HANDLE hTexture;//h表示handle,此变量为一句柄

/*
The LP prefix has been preserved to make it easier to port 16-bit code to 32-bit Windows. Today there is no distinction, and these pointer types are all equivalent. Avoid using these prefixes; or if you must use one, then use P.
*/
RECT*  rect;  // Pointer to a RECT structure.
LPRECT rect;  // The same, LP意思是Long Pointer,是16位windows系统的遗留产物,现在已经与p- prefix没有区别
PRECT  rect;  // Also the same, P意识是Pointer

// dw is short for DWORD(unsigned 32bits) and w is short for WORD.(unsigned 16bits)
wchar_t* // Unicode字符串(w表示wide,意思是wide characters16位) 与之对应的是ANSI字符串char*
PCSTR or LPCSTR  // 表示const char*
PWSTR or LPWSTR  // 表示wchar_t*

// To declare a wide-character literal or a wide-character string literal, put L before the literal.
wchar_t a = L'a';
wchar_t *str = L"hello";
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值