Amazon.com Widgets id question
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 12:41:28 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
|-+  Old Stuff
| |-+  Chapter Study
| | |-+  Chapter 9 - Polymorphism, Dynamic Typing, and Dynamic Binding
| | | |-+  id question
Pages: [1]   Go Down
Print
Author Topic: id question  (Read 645 times)
OC2000
Newbie
*
Posts: 5


Email




« on: July 13, 2011, 08:56:44 PM »

Hi,

Why does the underlined code not work?

 Square *mySquare = [[Square alloc]init];
 XYPoint *myPoint = [[XYPoint alloc]init];
   
    id dataValue1; 
    id dataValue2;
   
    dataValue1 = mySquare;
    dataValue2 = myPoint;

    [dataValue1 setSide:5]; // works fine
    [dataValue2 setX:100 andY:200]; // works fine

    dataValue1.origin = dataValue2 // This says that " Member reference type 'struct objc_object *' is a pointer;

    [dataValue1 print];
    [dataValue2 print];

    [mySquare release];
    [myPoint release];

Logged
bpedit
Jr. Member
**
Posts: 65


Email




« Reply #1 on: July 16, 2011, 02:12:13 PM »

Try changing the line to
   
Code: (Objective-C)
[dataValue1 setOrigin: dataValue2];
This tested out well for me. I'm not sure why the dot operator does not work in cases like this, it's happened to me before.
Logged
dharr19
Full Member
***
Posts: 175


Email




« Reply #2 on: August 05, 2011, 07:30:23 PM »

  Square *mySquare = [[Square alloc] init];
    XYPoint *myPoint = [[XYPoint alloc] init];
    
    [myPoint setX:5 andY:10];
    [mySquare setSide:5];
    
    id dataValue1;  
    id dataValue2;
    
    dataValue1 = mySquare;
    dataValue2 = myPoint;
    
    [dataValue1 setSide:5];
    [dataValue2 setX:100 andY:200];
    
    [dataValue1 setOrigin: dataValue2];
 
    
    if ( [dataValue1 isMemberOfClass: [Square class]] == YES)
        NSLog(@"mySquare is a member of Square class");
    
    if ( [dataValue2 isMemberOfClass: [XYPoint class]] == YES)
        NSLog(@"mySquare is a member of XYPoint class");


output

2011-08-05 22:28:31.084 GraphicObject[3513:707] dataValue1 is a member of Square class
2011-08-05 22:28:32.159 GraphicObject[3513:707] dataValue2 is a member of XYPoint class
« Last Edit: August 05, 2011, 07:32:14 PM by dharr19 » 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.