简体   繁体   English

C ++语法错误和缺少类型说明符

[英]C++ syntax error and missing type specifier

Visual C++ 2008 gives me this weird error, so I stripped out all of the excess stuff in my header file (util.h ), and it boils down to this: Visual C ++ 2008给了我这个奇怪的错误,所以我删除了头文件(util.h)中所有多余的东西,并将其归结为:

#ifndef UTIL_H
#define UTIL_H

void pause();

#endif

When I try to compile the above code I get this: 当我尝试编译上面的代码时,我得到了:

Compiling...
util.cpp
util.h(4) : error C2144: syntax error : 'void' should be preceded by ';'
util.h(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<snip>

I am deeply confused. 我很困惑。 Even if I comment out the ifndef, define, and endif, preprocessor directives, It still says the same thing. 即使我注释掉了ifndef,define和endif预处理程序指令,它仍然会说同样的话。

After hours of looking, I finally figured it out! 经过数小时的寻找,我终于明白了!

The error is not in the header file itself. 该错误不在头文件本身中。 Header files are copied and pasted into source files, where they are included. 头文件被复制并粘贴到源文件中(在其中包含它们)。 So I looked where I included the file, and I saw in util.cpp: 因此,我查看了包含文件的位置,并在util.cpp中看到了:

#include "stdafx.h"b
#include "util.h"
<snip>

That extra 'b' is causing the error. 多余的'b'会导致错误。 C++ thinks it is a variable, but doesn't see a type specifier, so it assumes 'b' is a new integer. C ++认为它是一个变量,但是没有看到类型说明符,因此它假定'b'是一个新的整数。 Then it thinks I should terminate its declaration with a ';' 然后它认为我应该以';'终止其声明';' to precede 'void' . 'void'之前。 The entire issue is just a stupid extra character, and a not very helpful error message. 整个问题只是一个愚蠢的多余字符,并且不是非常有用的错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C++ 缺少类型说明符:语法错误 - C++ Missing type specifier: syntax error C ++-错误C4430:缺少类型说明符(用于构造函数???) - C++ - Error C4430: missing type specifier (for a constructor???) 错误C4430:缺少类型说明符/错误C2143:语法错误:缺少&#39;;&#39; 在“ *”之前 - error C4430: missing type specifier / error C2143: syntax error : missing ';' before '*' 缺少类型说明符 - 在C ++中假设为Int - Missing Type Specifier - Int Assumed in C++ C ++缺少类型说明符-是否假定为int? - C++ Missing type specifier - int assumed? C2143:语法错误:缺少&#39;;&#39; &#39;*&#39;和C4430之前:缺少类型说明符-假定为int。 注意:C ++不支持default-int - C2143: syntax error: missing ';' before '*' & C4430: missing type specifier - int assumed. Note: C++ does not support default-int 错误C4430:缺少类型说明符 - error C4430 : missing type specifier 错误:缺少类型说明符 - Error: missing type specifier C ++:“错误C4430:缺少类型说明符 - 假设为int”对于构造函数和析构函数的无效声明 - C++: “error C4430: missing type specifier - int assumed” For constructor and invalid declaration for destructor shared-ptr 和错误 C4430:缺少类型说明符 - 假定为 int - C++ - shared-ptr and error C4430: missing type specifier - int assumed - C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM