- 浅层赋值:实现对象数据元素的一一复制
- 深层复制:当被复制的对象数据成员是指针类型时,不是符合该指针成员本身,而是将指针所指对象进行复制
深层复制
1.复制指针所指的对象
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include "stdio.h"
#include <cassert>
using namespace std;
class Point
{
private:
int a, b;
public:
Point():a(0),b(0){
cout << "Default call" << endl;
return ;
}
Point(int x, int y) : a(x), b(y){
cout << "Constructor called." << endl;
}
~Point(){
cout << "Destructor called." << endl;
}
int getX() const { return this->a; }
int gety() const { return this->b; }
void move(int nX, int nY){
a = nX;
b = nY;
}
};
class ArrayPoint
{
private:
Point *po; //指向动态数组首地址