【问题标题】:How to find the "real" error?如何找到“真正的”错误?
【发布时间】:2013-06-04 21:43:22
【问题描述】:

我在程序的错误列表中显示了大量错误,但列出的错误似乎都不是“真正的”错误。有些线是红色的,然后当我在它们上面突出显示时,错误消失了。我似乎无法找到我的错误到底在哪里。找出我的错误的最佳过程是什么?

以下是错误列表,以防万一。

    Error   38  error C1004: unexpected end-of-file found   85
Error   68  error C1004: unexpected end-of-file found   42
Error   63  error C1903: unable to recover from previous error(s); stopping    compilation  72
Error   66  error C2059: syntax error : ')' 42
Error   2   error C2059: syntax error : '>' 80
Error   40  error C2059: syntax error : '>' 80
Error   65  error C2059: syntax error : '>' 42
Error   20  error C2065: '_Ptr_cerr' : undeclared identifier    27
Error   16  error C2065: '_Ptr_cin' : undeclared identifier 25
Error   22  error C2065: '_Ptr_clog' : undeclared identifier    28
Error   18  error C2065: '_Ptr_cout' : undeclared identifier    26
Error   28  error C2065: '_Ptr_wcerr' : undeclared identifier   32
Error   24  error C2065: '_Ptr_wcin' : undeclared identifier    30
Error   30  error C2065: '_Ptr_wclog' : undeclared identifier   33
Error   26  error C2065: '_Ptr_wcout' : undeclared identifier   31
Error   4   error C2065: 'faction' : undeclared identifier  84
Error   42  error C2065: 'faction' : undeclared identifier  84
Error   64  error C2065: 'Faction' : undeclared identifier  42
Error   13  error C2065: 'socialite' : undeclared identifier    100
Error   51  error C2065: 'socialite' : undeclared identifier    100
Error   1   error C2065: 'Socialite' : undeclared identifier    80
Error   12  error C2065: 'Socialite' : undeclared identifier    100
Error   39  error C2065: 'Socialite' : undeclared identifier    80
Error   50  error C2065: 'Socialite' : undeclared identifier    100
Error   8   error C2065: 'textWriter' : undeclared identifier   82
Error   46  error C2065: 'textWriter' : undeclared identifier   82
Error   6   error C2143: syntax error : missing ',' before ')'  84
Error   10  error C2143: syntax error : missing ',' before ')'  82
Error   14  error C2143: syntax error : missing ',' before ')'  100
Error   44  error C2143: syntax error : missing ',' before ')'  84
Error   48  error C2143: syntax error : missing ',' before ')'  82
Error   52  error C2143: syntax error : missing ',' before ')'  100
Error   17  error C2143: syntax error : missing ',' before ';'  25
Error   19  error C2143: syntax error : missing ',' before ';'  26
Error   21  error C2143: syntax error : missing ',' before ';'  27
Error   23  error C2143: syntax error : missing ',' before ';'  28
Error   25  error C2143: syntax error : missing ',' before ';'  30
Error   27  error C2143: syntax error : missing ',' before ';'  31
Error   29  error C2143: syntax error : missing ',' before ';'  32
Error   31  error C2143: syntax error : missing ',' before ';'  33
Error   7   error C2143: syntax error : missing ';' before '{'  32
Error   15  error C2143: syntax error : missing ';' before '{'  10
Error   32  error C2143: syntax error : missing ';' before '{'  36
Error   35  error C2143: syntax error : missing ';' before '{'  27
Error   45  error C2143: syntax error : missing ';' before '{'  32
Error   54  error C2143: syntax error : missing ';' before '{'  34
Error   57  error C2143: syntax error : missing ';' before '{'  48
Error   60  error C2143: syntax error : missing ';' before '{'  61
Error   3   error C2143: syntax error : missing ';' before '}'  82
Error   11  error C2143: syntax error : missing ';' before '}'  98
Error   33  error C2143: syntax error : missing ';' before '}'  42
Error   34  error C2143: syntax error : missing ';' before '}'  45
Error   36  error C2143: syntax error : missing ';' before '}'  83
Error   37  error C2143: syntax error : missing ';' before '}'  85
Error   41  error C2143: syntax error : missing ';' before '}'  82
Error   49  error C2143: syntax error : missing ';' before '}'  98
Error   55  error C2143: syntax error : missing ';' before '}'  43
Error   58  error C2143: syntax error : missing ';' before '}'  57
Error   61  error C2143: syntax error : missing ';' before '}'  69
Error   67  error C2143: syntax error : missing ';' before '}'  42
Error   5   error C2275: 'Faction' : illegal use of this type as an expression  84
Error   43  error C2275: 'Faction' : illegal use of this type as an expression  84
Error   9   error C2275: 'std::ofstream' : illegal use of this type as an expression    82
Error   47  error C2275: 'std::ofstream' : illegal use of this type as an expression    82
Error   53  error C2653: 'Socialite' : is not a class or namespace name 33
Error   56  error C2653: 'Socialite' : is not a class or namespace name 46
Error   59  error C2653: 'Socialite' : is not a class or namespace name 60
Error   62  error C2653: 'Socialite' : is not a class or namespace name 72

【问题讨论】:

  • 始终自上而下工作 - 一旦原始解析问题得到解决,任何“后果性错误”都会自动消失。第一个是总是一个真正的错误。如果似乎没有涉及任何逻辑,请重新启动 Visual Studio,如果它已修复,请不要感到惊讶 - 内部缓存可能会被破坏。
  • 我如何确定实际的第一个错误,我在错误列表中使用哪种排序。这是针对 Visual Studios 2010 Express 的。
  • 我将猜测一些未终止的构造,例如稍后在同一文件中没有相应 #endif 的 #ifdef(XYZ)。或者没有相应的右大括号的左大括号。
  • 提示:找到报告错误的编号最小的行,然后从该行倒推。由于某些编译器实际上可以相当准确地查明解析出错的地方,因此请务必仔细查看您的输出。
  • 大多数第一个错误显然位于 中,这对我来说并没有多大意义。

标签: c++ visual-c++ compiler-errors


【解决方案1】:

可能丢失了;在类/结构的关闭 } 之后。可以发一些代码吗?

更新:代码现在在我的 gcc 上编译。我发现的问题是您的类之间存在循环依赖关系。所以解决这个问题,在标题中前向声明其中的一些。我在Socialite.hclass Socialite 之前添加了class Faction;,在Faction.hclass Faction 之前添加了class Socialite;

【讨论】:

  • 我只是将它添加到原始帖子中吗?总共有 7 个文件,不知道如何全部发布。
  • 或以 pastebin 为例
  • 能否也上传list.h
  • 这是一个头文件,我们可以使用它来完成程序。这是更新的粘贴箱。 pastebin.com/VUyPwfHE
  • 我想下次我有这样的事情时,在另一个编译器中运行代码可能会有所帮助。感谢您的帮助。
【解决方案2】:

文件意外结束通常是您缺少一个结束的“东西”,例如括号} 或括号)

【讨论】:

    【解决方案3】:

    可能是类型定义末尾缺少#endif;,也可能是函数末尾缺少}

    【讨论】:

      【解决方案4】:

      从报告的第一个错误开始。这通常是许多后续问题的原因,因为第一个错误会导致解析器与其余代码不同步。

      在 C++ 中,一连串错误通常是由未声明的类型(您是否忘记了包含文件?)或在类或结构定义后缺少 ; 引起的。

      考虑:

      Foobar fb;  // Declare an instance of Foobar.
      

      如果尚未声明 Foobar(可能是因为您忘记包含“foobar.h”),那么编译器可能会认为您正在尝试声明一个名为 Foobar 且默认类型为 int 的变量。从那里,它看到 fb 并感到很困惑。

      或者考虑:

      struct Foobar {
        int x;
        int y;
      }
      
      int blah = 0;
      

      如果在结构定义之后没有;,解析器会认为您正在尝试声明一个名为 int 的 Foobar 实例,这是不允许的,因为 int 是保留关键字。之后的一切对编译器来说都像是 gobbledegook。

      一个技巧是暂时#if 0-out 出现第一个报告错误的行之后的所有代码,因为这样可以减少噪音,直到您找出原始问题。

      【讨论】:

        【解决方案5】:

        如果您查看“错误列表”窗口(查看 > 错误列表),可能很难找出错误的来源。幸运的是,还有另一种方法:

        1. 打开“输出”窗口(调试 > 窗口 > 输出)
        2. 编译构建
        3. “输出”窗口的顶部开始,沿着编译器/链接器输出文本向下移动,直到出现第一行显示“错误”

        这通常会引导你解决问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-10-17
          • 1970-01-01
          • 2021-09-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-10-03
          相关资源
          最近更新 更多