如何修复 Typedef 变量未识别错误 C++ (Visual Studio 2017)

How to fix Typedef variable not identified error in C++ (Visual Studio 2017)

本文关键字:Visual Studio 2017 C++ 错误 Typedef 何修复 变量 识别      更新时间:2023-10-16

我在头文件中为现有数据类型定义了几个别名类型。在使用别名在我的代码(包括所述头文件(中定义变量时,别名不会被标识为类型。查找解决此错误的建议。语言 - C++, IDE - Visual Studio 2017

头文件中的定义:

#ifndef HD_DEFINES_H_DEFINE      
#define HD_DEFINES_H_DEFINE      
#include <limits.h>      
#ifdef __cplusplus      
extern "C"       
{      
#endif      
typedef unsigned int HDuint;      
typedef unsigned char HDboolean;      
typedef unsigned long HDulong;      
typedef unsigned short HDushort;      
typedef int HDint;      
typedef float HDfloat;      
typedef double HDdouble;      
typedef long HDlong;      
typedef char HDchar;      
typedef unsigned int HDerror;      
typedef unsigned int HDenum;      
typedef const char *HDstring;      
typedef unsigned int HHD;      
typedef struct      
{      
    HDerror errorCode; /* The HD_ error code */      
    int internalErrorCode; /* The original internal device-generated error */      
    HHD hHD; /* The handle of the current device when the error occurred */      
} HDErrorInfo;   

代码中的用法:(代码包括所述头文件(

#include <string.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <sstream>
#include <HL/hl.h>
#include <HD/hd.h>
#include <HD/hdDefines.h>
#include <HDU/hduError.h>
#include <HDU/hduVector.h>
#include <HDU/hduMatrix.h>
struct DeviceData{
    HDboolean m_buttonState;       
    hduVector3Dd m_devicePosition; 
    HDErrorInfo m_error
};

错误信息:

<error-type> HDboolean
variable "HDboolean" is not a type name

Typedefs 看起来非常好,所以,我最好的猜测是,由于一些 ifdef 混乱,例如意外地从另一个文件中复制和粘贴该 #ifndef HD_DEFINES_H_DEFINE,因此多个标头具有相同的定义(将导致第二个标头未包含在内(以及类似的东西。

检查你的东西是否真的被包含的方法相当简单,只需在有问题的typedef之前放一些垃圾。像这样:

foo foo foo
typedef unsigned char HDboolean;

然后再次生成项目。如果它没有失败,请开始查看您的 ifdefs 以及它们有什么问题。如果相关编译器支持"#pragma 一次",可以考虑使用它。