• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Newbie: Cannot use object as a parameter to a method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie: Cannot use object as a parameter to a method


  • Subject: Newbie: Cannot use object as a parameter to a method
  • From: "Michael S. Tashbook" <email@hidden>
  • Date: Thu, 22 Apr 2004 14:07:17 -0400

Apologies in advance for a real newbie question; I'm just getting into
Objective-C (having lived and breathed Java for the past few years), and
this is driving me batty. It's probably a stupid error or a
misconception on my part, so any and all guidance is appreciated. I've
tried to RTFM (well, at least one 'M': the first edition of O'Reilly's
"Learning Cocoa", despite its checkered reputation).

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).

rollAsInt doesn't have any parameters, but I keep getting an error
message that I can't use an object as a parameter to a method. As far as
I can tell from the O'Reilly book, I'm declaring and defining the method
properly for one that takes no parameters. If I were writing this in
Java, I would just do something like

int rollAsInt()
{ ... }

or in plain C:

int rollAsInt(void)
{ ... }

[admittedly, my C is a bit rusty, which may be causing the problem here]

I've tried adding a colon to the end of the method header (before the
curly braces), but no joy. How do I convince the compiler that my method
doesn't *have* any (explicit) parameters?

My code is below. I'd greatly appreciate any insight you can provide
that might set me back on the right track.

Thanks in advance,

Mike


CWDie.h:

#import <Cocoa/Cocoa.h>

@interface CWDie : NSObject
{
int currValue;
}

- (void)roll;

- (int)rollAsInt;
@end


CWDie.m:

#import "CWDie.h"

@implementation CWDie
- (void)roll
{
currValue = (rand() % 6) + 1;
NSLog(@"Rolled a %d.\n", currValue);
}

- (int)rollAsInt
{
return currValue; // This is where XCode complains of an error
}
@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.


  • Prev by Date: Re: International Languages List?
  • Next by Date: Re: Newbie: Cannot use object as a parameter to a method
  • Previous by thread: Re: International Languages List?
  • Next by thread: Re: Newbie: Cannot use object as a parameter to a method
  • Index(es):
    • Date
    • Thread