Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class String
- {
- int size;
- char* data;
- };
- String s1("Ace"); // s1.size = 3 s1.data=0x0000F000
- String s2 = shallowCopy(s1);
- // s2.size =3 s2.data = 0X0000F000
- String s3 = deepCopy(s1);
- // s3.size =3 s3.data = 0x0000F00F
- // (With Ace copied to this location.)
- char * Source = "Hello, world.";
- char * ShallowCopy = Source;
- char * DeepCopy = new char(strlen(Source)+1);
- strcpy(DeepCopy,Source);
- var source = { firstName="Jane", lastname="Jones" };
- var shallow = ShallowCopyOf(source);
- var deep = DeepCopyOf(source);
- source.lastName = "Smith";
- WriteLine(source.lastName); // prints Smith
- WriteLine(shallow.lastName); // prints Smith
- WriteLine(deep.lastName); // prints Jones
- struct sample
- {
- char * ptr;
- }
- void shallowcpy(sample & dest, sample & src)
- {
- dest.ptr=src.ptr;
- }
- void deepcpy(sample & dest, sample & src)
- {
- dest.ptr=malloc(strlen(src.ptr)+1);
- memcpy(dest.ptr,src.ptr);
- }
Add Comment
Please, Sign In to add comment