Shallow Copy and Deep
Shallow Copy and Deep
ABU ARMAN
ID :221311044
COURSE T-:OOP LANGUAGE
DEPT OF CSE
VARENDRA UNIVERSITY
RAJSHAHI
Shallow Copy and Deep Copy
in C++
Shallow Copy
SHALLOW COPY IS EASY ,WE DON’T
} NEED TO WRITE ANY CODE.
#include<iostream>
#include<conio.h> };
using namespace std; int main(){
class u{ u ob1(23,12);
int a,b; u ob2(ob1);
public:
}
obj2
SHALLOW COPY
int main(){
u ob1(23,12);
u ob2(ob1); COPY CONSTACTOR WILL DO COPY.
ob1.disp();
getch();
ob2.disp();
getch();
return 0; }
SHALLOW COPY
#include<iostream> u ob1(23,12);
#include<conio.h> u ob2(ob1);
Copy Constractor DO THIS
using namespace std; u ob3=ob1;
COPY
class u{ u ob4;
int a,b; ob4=ob1; ASSIGNMENT
public: ob1.disp(); OPERATOR DO THIS
DEFAULT getch(); COPY
u(){} CONSTRACTOR ob2.disp();
u(u &t){ getch();
a=t.a; ob3.disp();
Copy constractor
getch();
b=t.b;}
ob4.disp();
u(int x,int y){
return 0; COMPILER AUTO WRITE THIS
a=x;
} CODE.
b=y; }
void disp(){cout<<"a="<<a<<"\ WE DONT NEED TO WREITE
n"<<"b="<<b<<"\n; } THIS CODE MANUALLY & THIS
}; IS CALLED SHALLOW COPY
int main(){
DEEP COPY