如何找到“真实”错误?

时间:2013-06-04 21:43:22

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

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

以下是有用的错误列表。

    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

5 个答案:

答案 0 :(得分:6)

可能缺少;在一个类/结构的结束之后。你能发一些代码吗?

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

答案 1 :(得分:1)

文件的意外结束通常是您缺少结束“某事”,例如括号}或括号)

答案 2 :(得分:0)

在类型定义的末尾可能缺少#endif;,或者在函数末尾可能缺少}

答案 3 :(得分:0)

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

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

考虑:

Foobar fb;  // Declare an instance of Foobar.

如果还没有声明Foobar(也许是因为你忘了包含“foobar.h”),那么编译器可能会认为你试图用默认类型int声明一个名为Foobar的变量。从那里,它看到了fb并且让所有人感到困惑。

或者考虑一下:

struct Foobar {
  int x;
  int y;
}

int blah = 0;

在结构定义之后没有;,解析器认为你正在尝试声明一个名为int的Foobar实例,这是不允许的,因为int是一个保留关键字。之后的所有内容看起来都像gobbledegook到编译器。

一个技巧是暂时#if 0 - 在第一次报告错误的行之后输出所有代码,因为这会降低噪音,直到您找出原始问题为止。

答案 4 :(得分:0)

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

  1. 打开“输出”窗口(调试> Windows>输出)
  2. 编译和构建
  3. “输出”窗口的顶部开始,按照编译器/链接器输出文本的方式进行操作,直到找到“错误”的第一行
  4. 这通常会引导您解决问题。