您的位置:首页 > 编程语言 > C语言/C++

C++犄角旮旯之POD

2011-05-05 11:18 260 查看
所谓的POD是plain old data的缩写,就是c语言中的结构体。在c++中,POD类型不但用法和C语言中的结构体一样,且行为方式也

和C语言中的结构体一样。



c++规范是这样定义POD的

Objects of POD types with static storage duration initialized with constant expressions shall be initialized before any dynamic initialization takes place.



POD类型的对象没有默认拷贝赋值构造函数或不调用默认拷贝赋值构造函数。



如下代码所示

#include <iostream>
using namespace std;
class VPoint
{
public:
	double x;
	double y;
};
void main()
{
	VPoint pt={3.0, 6.0};
	VPoint pt2;
	pt2 = pt;
	/*
	//这是对应的汇编代码
	VPoint pt={3.0, 6.0};
	//将浮点数压入FPU的浮点寄存器栈中
	004114CE  fld         qword ptr [__real@4008000000000000 (417818h)] 
	//指令从FPU的浮点寄存器栈中弹出一个浮点数 存入指定的内存地址
	004114D4  fstp        qword ptr [pt] 
	004114D7  fld         qword ptr [__real@4018000000000000 (417808h)] 
	004114DD  fstp        qword ptr [ebp-0Ch] 
	VPoint pt2;
	pt2 = pt;
	004114E0  fld         qword ptr [pt] 
	004114E3  fstp        qword ptr [pt2] 
	004114E6  fld         qword ptr [ebp-0Ch] 
	004114E9  fstp        qword ptr [ebp-24h] 
	*/
	
	cout << pt.x << "," << pt.y << endl;
}




看它的汇编代码可知,POD类型对象要么没有默认拷贝赋值构造函数,要么不调用默认拷贝赋值构造函数。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: