Amazon.com Widgets code on pg 167
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2013, 09:34:22 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Chapter 8
| | |-+  code on pg 167
Pages: [1]   Go Down
Print
Author Topic: code on pg 167  (Read 425 times)
Cretan1986
Newbie
*
Posts: 4






« on: May 27, 2012, 02:49:47 PM »

The book has the following code:

Code: (Objective-C)
origin.x = pt.x;
origin.y = pt.y;

why to copy separately the instance variables instead the whole object like the following?

Code: (Objective-C)
origin = pt;
Logged
kritchens
Newbie
*
Posts: 10






« Reply #1 on: September 17, 2012, 05:07:09 PM »

The book has the following code:

Code: (Objective-C)
origin.x = pt.x;
origin.y = pt.y;

why to copy separately the instance variables instead the whole object like the following?

Code: (Objective-C)
origin = pt;

try this for yourself and see what happens if you do this. you will see it will have the same issue as program 8.5. the reason you need to assign each variable of origin is so that is gets its own copy of each instance variable of pt, vs setting origin to pt where now it basically references pt and will dynamically change based on pt's attributes being changed..
Logged
todrico
Newbie
*
Posts: 17


Email




« Reply #2 on: March 13, 2013, 02:08:04 PM »

So how do you keep up with it? What if you have 3 origin points.  How would you know which one you are accessing?
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

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 (c) 2009 classroomM.com. All rights reserved.