View Single Post
Raz0rEdge

 
Raz0rEdge's Avatar
 
Member Since: Jul 17, 2009
Location: MA
Posts: 7,325
Raz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant future
Mac Specs: 27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3

Raz0rEdge is offline
In the realm of C, you would use pointers to pass it's reference to a function as opposed to the value itself..

Your example above, (although buggy) is how you'd do it in C. The problem is that numberTwo has no "storage" that it's pointing to, so when you assign 14 to it, that becomes the "storage" and later one if you try to de-reference the pointer, the program will crash.

Within Objective-C, you still use pointers and you have to to be able to send messages to the class object..

For example:
Code:
Fraction *myFraction = [[Fraction alloc] init];
[myFraction somemethod];
The [] syntax in Obj-C is doing a bunch of work here..in the first line, it will call your Fraction class' alloc function, followed by init function. What is returned is a instance of the object fully initialized. You can now call other methods within that class with the second line and pass in any arguments and so on.

Pointers are very useful constructs..so much so that certain languages make EVERYTHING a pointer (visibly or not)..but there're also a lot of easy pitfalls to get into..

Regards
QUOTE Thanks