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

由”构造函数“引发的一系列的。。

2013年10月28日 ⁄ 综合 ⁄ 共 402字 ⁄ 字号 评论关闭

转自:http://blog.csdn.net/hannea/article/details/8091029

#include<iostream>
using namespace std;

class test{
	typedef struct node{
		//条件:1.位域中冒号后面的数值不能超过冒号前面变量类型所占空间的位(bit)数
		//      2.位域成员不能使用sizeof()求值
		//注意:变量类型顺序对内存空间大小的分配也会产生影响
		//      如下分配8个字节:
		char i:5;
		int k:3;
		int j:2;
		//5+27+3+2+27=64bit=8Byte


		//      如下分配12个字节:
		int k:3;
		char i:5;		
		int j:2;
		//3+29+5+27+2+30=96bit=12Byte
	}node;

public:
	test(){ 
		cout << sizeof(node) << endl;
	}
};

int main()
{ 
	test a;
	return 0;
}

抱歉!评论已关闭.