嵌套函数被禁用;使用 f 嵌套函数重新启用

发布于 2024-10-16 05:14:03 字数 469 浏览 2 评论 0原文

我刚刚学习 Objective C,遇到了很大的困难。这就是我输入的内容,它给了我一个错误。我输入了粗体文本。有什么问题呢。它在 int main(void) 之后给了我嵌套函数错误

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [NSAutoreleasePool alloc] init];

// **#include <stdio.h>
int main(void)
int amount = 1000000;
printf("The amount in your account is $%i\n", amount);
return 0;
}**
NSLog(@"Hello, World!");
[pool drain];
return 0;
}

I am just learning Objective C and I am having great difficulty. This is what is typed and it is giving me an error. I typed the text that is bold. What is wrong with it. It gives me the nested function error right after int main(void)

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [NSAutoreleasePool alloc] init];

// **#include <stdio.h>
int main(void)
int amount = 1000000;
printf("The amount in your account is $%i\n", amount);
return 0;
}**
NSLog(@"Hello, World!");
[pool drain];
return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏月而来 2024-10-23 05:14:03

你的问题是 C 及其兄弟不喜欢函数中的函数(暂时搁置 gcc 扩展)。

您似乎想要做的是在您的 main 中声明一个全新的main。这是一个很大的禁忌。我怀疑您已将整个 C 程序剪切并粘贴到现有 main 的中间。

从:开始

#import <Foundation/Foundation.h>
#include <stdio.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [NSAutoreleasePool alloc] init];
    int amount = 1000000;
    printf("The amount in your account is $%i\n", amount);
    NSLog(@"Hello, World!");
    [pool drain];
    return 0;
}

,然后从那里开始努力。

Your problem is that C and it's brethren do not like functions within functions (putting aside gcc extensions for now).

What you seem to be trying to do is to declare a whole new main inside your main. That's a big no-no. What I suspect is that you've cut-and-pasted an entire C program into the middle of your existing main.

Start with:

#import <Foundation/Foundation.h>
#include <stdio.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [NSAutoreleasePool alloc] init];
    int amount = 1000000;
    printf("The amount in your account is $%i\n", amount);
    NSLog(@"Hello, World!");
    [pool drain];
    return 0;
}

and work your way up from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文