C++ 错误:输入结束时应为“}”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6364886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 19:59:29  来源:igfitidea点击:

error: expected ‘}’ at end of input

c++compiler-errorssyntax-error

提问by Dialecticus

I have the following code:

我有以下代码:

#include <libubuntuone-1.0/u1-music-store.h>
#include <libsyncdaemon-1.0/libsyncdaemon/syncdaemon-authentication.h>
#include <libsyncdaemon-1.0/libsyncdaemon/syncdaemon-credentials.h>
#include <libsyncdaemon-1.0/libsyncdaemon/syncdaemon-daemon.h>

static void
get_credentials (U1MusicStore *music_store,
                                 gchar **oauth_consumer_token,
                                 gchar **oauth_consumer_secret,
                                 gchar **oauth_token,
                                 gchar **oauth_token_secret)
{
    SyncdaemonCredentials *credentials;
    *oauth_consumer_token = *oauth_consumer_secret = *oauth_token = *oauth_token_secret = NULL;

    *oauth_consumer_token = g_strdup (syncdaemon_credentials_get_consumer_key (credentials));
    *oauth_consumer_secret = g_strdup (syncdaemon_credentials_get_consumer_secret (credentials));
    *oauth_token = g_strdup (syncdaemon_credentials_get_token (credentials));
    *oauth_consumer_secret = g_strdup (syncdaemon_credentials_get_token_secret (credentials));
}

int main() 
{
    return 0;
}

and the only thing preventing it from compiling is the error message specified in the title of this question. The problem line has been identified as the closing brace of the mainfunction, but that obviously isn't the case, and I can't see where else I could have missed out any parentheses. Can anyone else spot what I'm doing wrong here?

唯一阻止它编译的是此问题标题中指定的错误消息。问题行已被确定为main函数的右大括号,但显然情况并非如此,而且我看不出还有什么地方可能遗漏了任何括号。其他人能发现我在这里做错了吗?

回答by George Gaál

In case of such errors it is good idea to localize error. You can do it simply, by commenting blocks of code.

如果出现此类错误,最好对错误进行定位。您可以通过注释代码块来简单地做到这一点。

In this example you can comment body get_credentialsfunction and check what will happen.

在这个例子中,你可以评论 bodyget_credentials函数并检查会发生什么。

Also good idea to paste empty line at the end of source code file.

在源代码文件的末尾粘贴空行也是个好主意。

回答by Dialecticus

Maybe some of the included headers has mismatched braces.

也许一些包含的标题有不匹配的大括号。

Maybe the compiler is bad at handling files with non-empty last line, and there is such line in some of the files.

也许编译器不擅长处理最后一行非空的文件,并且在某些文件中存在这样的行。

Try commenting out as much as you can (especially all includes) to make it compile, and then putting code back in until you localize the problem.

尝试尽可能多地注释掉(尤其是所有包含)以使其编译,然后将代码放回原处,直到您将问题本地化。