构造函数,拷贝构造函数,移动构造函数
作者:互联网
#include "stdafx.h"
#include <iostream>
using namespace std;
class Image
{
public:
Image()
{
cout << "construct !\n";
};
Image(const Image & inImg)
{
m_pBuf = inImg.m_pBuf;
m_nImgSize = inImg.m_nImgSize;
}
Image(const Image & inImg)
{
m_pBuf = inImg.m_pBuf;
m_nImgSize = inImg.m_nImgSize;
inImg.m_pBuf = NULL;
};
void allocBuff()
{
m_pBuf = new char[100];
}
~Image()
{
if (NULL != m_pBuf)
{
delete m_pBuf;
m_pBuf = NULL;
}
cout << "desconstruct !";
};
private:
char *m_pBuf;
int m_nImgSize;
};
int main()
{
Image * pImgA = new Image();
pImgA->allocBuff();
Image * pImgB = new Image(*pImgA);
if (NULL != pImgA)
{
delete pImgA;
pImgA = NULL;
}
return 0;
}
标签:pImgA,Image,pBuf,NULL,inImg,nImgSize,拷贝,移动,构造函数 来源: https://blog.csdn.net/sjkscetc/article/details/110119758