Amazon.com Widgets What's wrong with this code snippet?
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 26, 2014, 01:29:43 AM
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 13 - Underlying C Language Features
| | | |-+ What's wrong with this code snippet?
Pages: [1] Go Down
Print
Author Topic: What's wrong with this code snippet? (Read 1343 times)
verybadcat
Newbie
*
Posts: 14






on: September 09, 2009, 09:18:43 AM

I think this should work, but it doesn't.  I must be missing something very basic.

const NSString words[] = {@"Happy", @"Birthday"};
NSString *word;
word = @"Birthday";
word = words[1];   

At the last line, the compiler says "error: incompatible types in assignment."  But words[1] is @"Birthday".  So why is it OK to set word equal to @"Birthday" but not OK to set it equal to words[1]?
Logged
rgronlie
Global Moderator
Full Member
*****
Posts: 212







Reply #1 on: September 09, 2009, 10:37:06 AM

Just as word is a pointer to an NSString object, words needs to be an array of pointers to NSString objects.
You forgot the *

const NSString *words[] = {@"Happy", @"Birthday"};
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.