メインファイルに次がある場合
int main ( int argc, const char * argv[])
{
@autoreleasepool
{
Complex * c1 = [[Complex alloc] init];
Complex * c2 = [[Complex alloc] init];
Complex * compResult;
compResult = [c1 add: c2];
[compResult print];
{
return0;
{
/**implementation of add method **/
-(Complex *) add: (Complex *) f
{
Complex *result = [[Complex alloc] init]
result.real = real + f.real;
result.imaginary = imaginary + f.imaginary;
return result;
}
c1 と c2 がオブジェクトであることはわかっていますが、compResult = [c1 add: c2]; を実行するまでは、compResult は変数と見なされます。
ここでの私の仮定は、add メソッドが Object を返し、compResult = [c1 add: c2]; を実行することです。compResult をそのオブジェクトと等しく設定しています。それでは、compResult をオブジェクトに変換しますか?
したがって、私の考えでは、compResult は [c1 add: c2] の結果を受け取る変数ですが、[compResult print] を実行すると、メッセージを送信するときにのみこの構文を使用できると思っていたので、本当に混乱します (この中でケースプリント)オブジェクトに?
私の主な質問は、compResult = [c1 add: c2]; を実行した後であると思います。オブジェクトを保持/表す変数 compResult ですか、それとも実際にオブジェクトになりますか????