Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
June 27, 2017, 08:44:23 PM *
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: What's wrong with this code snippet?  (Read 2069 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:  

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.