Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
July 23, 2017, 03:41:20 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Return Assignment Question  (Read 1360 times)
jonthornham
Full Member
***
Posts: 169



WWW Email
« on: September 22, 2009, 07:06:09 PM »

I am going through Chapter 17 and watching the inheritance webcast and have a question.

Is the following:

Code: (Objective-C)
Fraction *myFrac = [[Fraction alloc] init];
Fraction *myFrac2;

[myFrac setTo:1 over: 8];

myFrac = myFrac2; //These reference the same place in memory.

equivalent to a returned Fraction? For example if a Fraction called answer from the Fraction add method is returned to result which is not allocated and initialized.

Since setting myFrac = myFrac2 does not increase the reference count a release of myFrac2 would release myFrac. I think this is the same for a returned Fraction I am just making sure.

Thanks,

Jon
Logged

Jon Thornham
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #1 on: September 22, 2009, 07:16:59 PM »

Jon,

Yes, it's the same principle as the Program 7.5/7.6 discussion.  However, your assignment is reversed, and should be:

Code: (Objective-C)
myFrac2 = myFrac;        //These reference the same place in memory.

Cheers,

Steve Kochan
Logged
jonthornham
Full Member
***
Posts: 169



WWW Email
« Reply #2 on: September 22, 2009, 08:07:19 PM »

Thanks. That clear up a lot about return.

Take care,

Jon
Logged

Jon Thornham
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.