| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
Why does the declaration of a pointer to an object look like this
Fraction *aFraction;
instead of like this
(Fraction *) aFraction;
-----------------
I’m reading Kochan’s book “Programing in Objective-C” and have come across pointers. What confuses me is the syntax associated with pointers. For instance Kochan defines a class called Fraction and uses it in the main program like this:
Fraction *aFraction = [[Fraction alloc] init];
which I read as “create a Fraction object and let the pointer aFraction of type Fraction point to it”.
Now if I understand things correctly the above line is equivalent to the following two lines of code
Fraction *aFraction;
aFraction = [[Fraction alloc] init];
and not to
Fraction *aFraction;
*aFraction = [[Fraction alloc] init];
In the line
Fraction *aFraction;
the Fraction is the type and aFraction is a variable. In my mind it seems that the asterisk belongs more to the type Fraction then to the variable aFraction.
Look at the following line of code:
-(Fraction *) add: (Fraction *) f
Here we are declaring a method that takes a fraction object as input and returns a fraction object as output. Here we clearly see that the asterisk belongs more to the type Fraction then to the variable f.
So if I was to define the syntax of C I would rather define the declaration of a pointer like this:
(Fraction *) aFraction;
But when K&R defined the syntax of C they used (what from my naive point of view doesn’t seem logical)
Fraction *aFraction;
So my question is why the syntax for pointers looks like it does. Is there any logical explanation.
Thanks Bob
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden
This email sent to email@hidden
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.