Re: Newbie: Cannot use object as a parameter to a method
Re: Newbie: Cannot use object as a parameter to a method
- Subject: Re: Newbie: Cannot use object as a parameter to a method
- From: "Michael S. Tashbook" <email@hidden>
- Date: Thu, 22 Apr 2004 15:04:01 -0400
>
On 22 Apr 2004, at 19:07, Michael S. Tashbook wrote:
>
> I'm trying to create a simple class that represents a six-sided die.
>
> XCode keeps complaining about my rollAsInt method, which is just
>
> supposed to return the value of the currValue instance variable (the
>
> code below omits a similar method that returns the value as an
>
> NSString,
>
> which gives the same error message).
Hmmm... That's odd. Everything seems to work fine when I comment out the
*other* method in my class; I had previously omitted it because it
generated the same error message, and I figured that there was something
more general to blame.
Here are my two class source code files, in their entirety. When I
uncomment the rollAsString method, I get the original "Can not use an
object as a parameter to a method" error message.
As a side note, XCode also reports that rollAsString has an incompatible
return type. According to the O'Reilly book, the @"" form should
automatically create an NSString object, which is what the method is
declared to return. Did I miss a memo somewhere? ;)
Any ideas?
Mike
CWDie.h:
/* CWDie */
#import <Cocoa/Cocoa.h>
@interface CWDie : NSObject
{
int currValue;
}
- (void)roll;
- (int)rollAsInt;
- (NSString)rollAsString;
@end
CWDie.m:
#import "CWDie.h"
@implementation CWDie
- (void)roll
{
currValue = (rand() % 6) + 1;
NSLog(@"Rolled a %d.\n", currValue);
}
- (int)rollAsInt
{
return currValue; // XCode reports the error here
}
- (NSString)rollAsString
{ // XCode reports the error here
return @"foo"; // Just a placeholder statement for now
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.