深複製:複製物件時,如果物件中包含物件型別的例項變數,要對物件型別的例項變數也要做物件複製。新物件中的物件型別例項變數和舊物件中的物件型別例項變數指的是不同的物件。不管任何一方例項變數對物件做修改,都互相不影響對方所指向的物件的內容。
.**件
1.m檔案03-物件複製3//
4//created by ma c on 15/8/14.5//
6//78
#import910
@inte***ce person : nsobject11 @property(nonatomic,copy)nsmutablestring *name;//
(copy)深拷貝
12@property(nonatomic,assign)nsinteger age;
13 -(id)initwithname:(nsmutablestring*)name andage:(nsinteger)age;
14 -(void
)show;
15@end
//.m主函式person.m
//03-物件複製
////
created by ma c on 15/8/14.
////
#import
"person.h
"@implementation
person
-(id)initwithname:(nsmutablestring*)name andage:(nsinteger)age
return
self;
}-(void
)show
-(void
)dealloc
-(id)copywithzone:(nszone *)zone
@end
1測試結果如下:03-物件複製3//
4//created by ma c on 15/8/14.5//
6//78
#import
9#import
"person.h"10
int main(int argc, const
char *ar**)
40return0;
41 }
2015-08-14程式猿神奇的手,每時每刻,這雙手都在改變著世界的互動方式!16:54:53.912
03-物件複製[1512:99948] name:tom,age:20
2015-08-14
16:54:53.913
03-物件複製[1512:99948] name:tomjerry,age:21
2015-08-14
16:54:53.913
03-物件複製[1512:99948] name:tom,age:20
2015-08-14
16:54:53.913
03-物件複製[1512:99948] name:tom,age:20
2015-08-14
16:54:53.914
03-物件複製[1512:99948] name:tom,age:20
2015-08-14
16:54:53.914
03-物件複製[1512:99948] name:tom,age:20
program ended with exit code:
0
Objective C 淺拷貝和深拷貝
iphone開發語言objective c是一種簡單的計算機語言,簡稱oc,支援複雜南通的物件導向程式設計。objective c語言,通常寫作objc和較少用的objective c或obj c,是擴充c的物件導向程式設計語言。它主要使用於mac os x和gnustep這兩個使用openstep...
Python深複製淺複製or深拷貝淺拷貝
簡單點說 1.copy.copy 淺拷貝 只拷貝父物件,不會拷貝物件的內部的子物件。2.copy.deepcopy 深拷貝 拷貝物件及其子物件 用乙個簡單的例子說明如下 import copy a 1,2,3,4,a b c b a c copy.copy a d copy.deepcopy a 很...
js 深複製(深拷貝)和淺複製(淺拷貝)的區別
最近在做專案的時候,發現deepcopy 這個函式,顧名思義是深複製的意思,有了深複製反向思考肯定有淺複製,查閱資料之後便做下整理 個人理解,深複製和淺複製最根本的區別在於 是否是真正獲取了乙個物件的複製實體而不是乙個引用 從深層次上講深複製在計算機中開闢了一塊記憶體位址用於存放複製的物件,而淺複製...