stdlib.h
#ifndef _countof
#define _countof __crt_countof
#endif
vcryntime.h
#ifdef __cplusplus
extern "C++"
{
template <typename _CountofType, size_t _SizeOfArray>
char (*__countof_helper(_UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
#define __crt_countof(_Array) (sizeof(*__countof_helper(_Array)) + 0)
}

本文详细解析了_crt_countof宏在C++中的定义和工作原理,通过示例和C++ Primer的解释,阐述了如何利用模板和 sizeof 操作符来确定数组的大小,并指出在使用中的注意事项。
最低0.47元/天 解锁文章
6302

被折叠的 条评论
为什么被折叠?



