I have this declaration in my header:
- (char*) randomCharGenerator;
And the method itself:
- (char*) randomCharGenerator {
char *letter;
return letter;
}
From what I read on the tutorial on CocoaDevCentral (http://cocoadevcentral.com/d/learn_objectivec/), I’m trying to call it like this:
char *tempLetter;
tempLetter = [char randomCharGenerator];
But I get the error: “Expected expression.” What am I doing wrong?
Where you have
you need to replace
charwith an instance of the class for which you defined therandomCharGeneratermethod.This is because in this declaration:
The
-at the beginning denotes thatrandomCharGeneratoris an instance method of whatever class it’s in, so it needs to be sent to an instance of your class. If you had replaced the-with a+, you would want to send therandomCharGeneratormessage to the class, as opposed to an instance of your class.Note that
charis a C data type, not an Objective-C class or object, so you can’t send it messages. So no expression of the form[char foo]is syntactically correct.