简体   繁体   English

错误C4430:缺少类型说明符

[英]error C4430 : missing type specifier

When trying to compile this project, I get 2 errors that I can't figure how to solve. 尝试编译该项目时,出现2个无法解决的错误。

1>initialization.h(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>initialization.h(6): error C2146: syntax error : missing ',' before identifier 'diskSpaceNeeded'

Here is the file where the error happens: 这是发生错误的文件:

Initialization.h 初始化h

#pragma once
extern bool CheckStorage(const DWORDLONG diskSpaceNeeded);

Initialization.cpp 初始化文件

#include "Initialization.h"
#include "../Main/EngineStd.h"
#include <shlobj.h>
#include <direct.h>

//
// CheckStorage
//
bool CheckStorage(const DWORDLONG diskSpaceNeeded)
{
    // Check for enough free disk space on the current disk.
    int const drive = _getdrive();
    struct _diskfree_t diskfree;

    _getdiskfree(drive, &diskfree);

    unsigned __int64 const neededClusters = 
        diskSpaceNeeded /(diskfree.sectors_per_cluster*diskfree.bytes_per_sector);

    if (diskfree.avail_clusters < neededClusters)
    {
        // if you get here you don’t have enough disk space!
        ENG_ERROR("CheckStorage Failure: Not enough physical storage.");
        return false;
    }
    return true;
}

I think it's something wrong with the includes, but I can't find where the error is occurring. 我认为include有点问题,但是我找不到错误发生的地方。

Your Initialization.h uses DWORDLONG which is not part of the C++ standard. 您的Initialization.h使用DWORDLONG ,它不是C ++标准的一部分。 This means you need to define it before you can use it. 这意味着您需要先定义它,然后才能使用它。

However, your Initialization.cpp includes Initialization.h first and then includes ../Main/EngineStd.h which defines the Windows specific stuff. 但是,您的Initialization.cpp首先包含Initialization.h,然后包含../Main/EngineStd.h,后者定义Windows特定的内容。 Therefore the compiler complains when trying to parse the includes in the order you gave them. 因此,编译器在尝试按给定它们的顺序解析包含时会抱怨。

This is also the reason why it works when you switch the order to include ../Main/EngineStd.h before Initialization.h. 这也是为什么当您在Initialization.h之前将顺序切换为包括../Main/EngineStd.h时它起作用的原因。

It is usually considered good practice that include files include the things that they are using by themselves. 通常认为,包含文件包含文件本身正在使用的内容的良好做法。 So your Initialization.h should contain an include directive for the file that is defining DWORDLONG . 因此,您的Initialization.h应包含定义DWORDLONG的文件的include指令。 Your current solution might work but it will give you a headache when you try to include Initialization.h somewhere else and don't remember which other includes it requires. 您当前的解决方案可能会起作用,但是当您尝试将Initialization.h包含在其他位置并且不记得需要其他哪个包含项时,它将使您头疼。

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

相关问题 C ++-错误C4430:缺少类型说明符(用于构造函数???) - C++ - Error C4430: missing type specifier (for a constructor???) 几个“错误C4430:缺少类型说明符”错误消息 - Several “Error C4430: missing type specifier” error messages 缺少类型说明符-int假定C4430错误 - missing type specifier - int assumed C4430 error 错误 C4430:缺少类型说明符 - 假定为 int - error C4430: missing type specifier - int assumed vtkStandardNewMacro 给出错误 C4430:缺少类型说明符 - vtkStandardNewMacro gives error C4430: missing type specifier 错误C4430:缺少类型说明符/错误C2143:语法错误:缺少&#39;;&#39; 在“ *”之前 - error C4430: missing type specifier / error C2143: syntax error : missing ';' before '*' 字符串无法识别? C4430:缺少类型说明符-假定为int - string not recognized? C4430: missing type specifier - int assumed 在模板函数中“C4430:缺少类型说明符 - 假定为int” - “C4430: missing type specifier - int assumed” in a template function 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