现在的位置: 首页 > 综合 > 正文

计算结构/类中的数据成员的偏移

2014年01月01日 ⁄ 综合 ⁄ 共 365字 ⁄ 字号 评论关闭

#include <iostream.h>
#pragma pack(1)
class test
{
 public:
 virtual ~test();
 int a;
 double d;
 float c;
 long long l;
};
#pragma pack()

template< class class_type,
          class data_type1>
void
sizeofshifttype(
   data_type1 class_type::*mem1)
{
   cout<<( (int)mem1)<<endl;
}
int main()
{
 sizeofshifttype(&test::a);
 sizeofshifttype(&test::d);
 sizeofshifttype(&test::c);
 sizeofshifttype(&test::l);
}

 

【上篇】
【下篇】

抱歉!评论已关闭.