The *
symbol has multiple meanings (beside multiplication :):
Dereference (follow) pointers. This code follows pointer stored in pointerToInt
and then assigns a value to it.
(*pointerToInt) = 5;
Declares a pointer type. When you write int *
it means “reference to an integer”.
int x = 5;
int * xPtr = &x
Now, objects are a kind of structures, but we only manipulate with them via pointers. Never directly. This basically means, that 99% of time when you see *
(and it's not multiplication :) it is the second case: a part of type declaration:
NSString *
= pointer to NSString
structure (you can't use NSString
alone)
Fraction *
= pointer to Fraction
structure and Fraction
structure is described in Fraction
class
So it's not “pointer to the Fraction class”, but rather “pointer to structure of Fraction class”.
I will go a little further and answer your future question about two **
. You may see this usually with NSError
arguments that are defined like methodWithError:(NSError **)errorPtr
.
Short story: int
is to int *
as NSError *
is to NSError **
.
Long story: If we cannot manipulate with objects directly (without pointers to them), the single pointer becomes standard part of declaration. Now what if we want to make indirect access to the object? We use double pointer! First *
is required for object, second is for indirection.
NSError *error = nil; // Empty.
NSError **errorPtr = &error; // Reference to our local `error` variable.
[data writeToURL:URL options:kNilOptions error:errorPtr];
// That method uses: (*errorPtr) = [NSError errorWith...];
NSLog(@"Error: %@", error); // Our local error is no longer empty.
I believe pointers are weird when you come from Java. They are a bit of legacy from C, but they are not used in any crazy way.