私が読んでいる「ココアデザインパターン」の本によると、保持機能は次のようなものを使用して実装されていると思います:
- (int)retainCount
// Returns the receiver's current reference count
{
int result = 1; // receiver not in table, its count is 1
void *tableValue = NSMapGet(
[[self class] _myRefCountMapTable], self);
if(NULL != tableValue )
{ // if receiver is in table, its count is the value stored
result = (int)tableValue;
}
return result;
}
- (id)retain
// Increases the receiver's reference count
{
// store the increased value in the table
NSMapInsert([[self class] _myRefCountMapTable], self,
(void *)([self retainCount] + 1));
return self;
}
例が示すように、すべての参照オブジェクトは同じ self メンバーを持ちます。それはどのように起こりますか?たぶん私はselfの意味を理解していません-C++で「これ」のようなものだと思います。
代入演算子 (A=B) だけを使用すると、ポインター (自己) がコピーされますか? 「copywithzone」を使用すると思いますが、それは親戚であり、「自己」メンバーは等しくありません。また、copywithzone は c++ のコピー コンストラクターのようなものだと思います。
私は2つの世界の間で混乱していると思います。