【问题标题】:error: expected ‘}’ at end of input错误:输入结束时应为“}”
【发布时间】:2011-09-15 22:22:06
【问题描述】:

我有以下代码:

#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;
}

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

【问题讨论】:

  • 上面的代码我还没有读完,但也请检查你的头文件。你确定他们都没事吗?
  • 注释掉get_credentials()的正文是否编译?实际上更进一步,注释掉除#include headers 之外的所有内容。标头应自行编译,否则可能会在某处出现杂散的“{”。
  • 你能发布整个错误吗?
  • @Brian,谢谢,我现在检查一下。 @Victor,不,它仍然失败。我要检查头文件。我没有检查它们,因为它们不是我编写的,并且已经在生产代码中使用,所以我只是假设它们会很好。

标签: c++ compiler-errors syntax-error


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    可能某些包含的标头的大括号不匹配。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 2020-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多