Amazon.com Widgets 4.3 answer I get is d = d but I get 4 warnings in Letter.m file
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 18, 2013, 09:34:11 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
| |-+  Answers to Exercises
| | |-+  Chapter 4
| | | |-+  4.3 answer I get is d = d but I get 4 warnings in Letter.m file
Pages: [1]   Go Down
Print
Author Topic: 4.3 answer I get is d = d but I get 4 warnings in Letter.m file  (Read 743 times)
My2CentsWorth
Newbie
*
Posts: 49


Mark






« on: March 08, 2010, 08:52:40 PM »

The 4 warnings are on Letter.m 2 on line 15, and 2 on line 19



Letter.h

Code: (Objective-C)
#import <Foundation/Foundation.h>

//------@interface section---------

@interface Letter : NSObject
{
char c;
char d;
}

-(void) setC: (char) c;
-(void) setD: (char) d;
-(char) c;
-(char) d;


@end
Letter.m

Code: (Objective-C)
#import "Letter.h"


//-----@implementation section-----

@implementation Letter

-(void) print
{
NSLog(@"%c C %c D", c, d);
}

-(void) setC:(char)c
{
c = c;
}
-(void) setD:(char)d
{
d = d;
}

-(char) c
{
return 'd';
}

-(char) d
{
return c;
}


@end

Letter1.m

Code: (Objective-C)
#import <Foundation/Foundation.h>
#import "Letter.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

/* 4.3 What output would you expect from the folowing program? */


//---Test and Run Here----

Letter *myLetter = [[Letter alloc] init];

[myLetter setC: 'c'];
[myLetter setD: 'd'];

NSLog(@"d = %c", 'd');

[myLetter release];

    [pool drain];
    return 0;
}


Letter1 - Debugger Console Output:

Code: (Objective-C)
2010-03-08 19:43:59.604 Letter1[26664:a0f] d = d


OOPS - sorry about that here is the corrected Letter.h @interface section
« Last Edit: March 09, 2010, 11:07:29 AM by My2CentsWorth » Logged

Donate your unused CPU time to better the world we live in @ http://www.worldcommunitygrid.org/
skochan
Administrator
Hero Member
*****
Posts: 3109







« Reply #1 on: March 09, 2010, 09:47:50 AM »

You have two implementation sections here.   Where is the interface section?

Cheers,

Steve
Logged
My2CentsWorth
Newbie
*
Posts: 49


Mark






« Reply #2 on: March 09, 2010, 11:10:45 AM »

You have two implementation sections here.   Where is the interface section?

Cheers,

Steve


Sorry about that Steve I modified it to show the correct code.
Logged

Donate your unused CPU time to better the world we live in @ http://www.worldcommunitygrid.org/
rgronlie
Global Moderator
Full Member
*****
Posts: 212







« Reply #3 on: March 09, 2010, 01:45:43 PM »

It would help when you say there is a warning that you post the warning message.

But looking at the code you are using the same name for both the instance and argument variables.
The warning is likely telling you that one is masking the other.

Use different names.

Ryan
Logged

Sanity: Minds are like parachutes. Just because you've lost yours doesn't mean you can borrow mine.
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.