如何修复 Typedef 变量未识别错误 C++ (Visual Studio 2017)
How to fix Typedef variable not identified error in C++ (Visual Studio 2017)
我在头文件中为现有数据类型定义了几个别名类型。在使用别名在我的代码(包括所述头文件(中定义变量时,别名不会被标识为类型。查找解决此错误的建议。语言 - 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 一次",可以考虑使用它。
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual Studio mkl_link_tool.exe链接错误
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 不同的Visual Studio版本中缺少.dll
- 用Visual Studio在C++中嵌入Julia
- Visual Studio 2017循环自动向量化问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- Visual Studio在尝试读取resource.txt文件时崩溃
- Visual Studio 2017 不允许我创建 C++ 专用模板