Hey there, I’m sort of new to Objective-C, and well, programming in general. I have a little experience in C# and c++, to give you a bit of a background. I’m using Xcode to create a simple application that adds 2 fields and returns a sum, and I’ve narrowed it down to one error:
“Nested functions are disabled, use -fnested-functions to re-enable”
Here’s the bit of code I’m having trouble with, any suggestions would be greatly appreciated:
-(IBAction)click:(id)sender;
{
int main (int argc, const char *argv[]){
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int sum;
sum = myInt1, myInt2;
NSLog (name, @", the answer is %i", sum);
[pool drain];
return 0;
}
}
What you are trying to do here is something which is not generally allowed in C languages. You, in general, cannot create a function inside of another one, like you can in languages like Pascal and JavaScript. You should remove the main stuff from inside
click:and just keeps the linesOn a broader, note, though, why are you trying to create a main inside of
click:? In Objective-C you normally usemain()just to create any root-level objects and instantiate the autorelease pool. Assuming you’re working with Xcode on a Mac, if you use one of the templates to get started it should take care of all the details for you of creating main. I’d suggest taking a look at Apple’s Cocoa tutorials to help you get a feel for how a typical Objective-C application is structured.