错误C7626: typedef name中使用的未命名类不能声明非静态数据成员以外的成员



我在VS2022中使用c++来构建项目。我必须包含来自名为eve.h的sdk的头文件。我已经添加了包含文件夹保存这个文件到项目属性。然而,当我构建这个项目时,我得到了一些C7626错误,说明以下内容,并指向eve.h文件的某些行。

Error   C7626   unnamed class used in typedef name cannot declare members other than non-static data members, member enumerations, or member classes (compiling source file main.cpp)       

错误指向的其中一行代码如下:

typedef struct
{
int isOpen;
int clearAll;
int clearSome;
int buttonFifty=-1;
int buttonTwenty=-1;
}ALL_Buttons;

这是sdk中的头文件,不是我的代码。我以前从来没有遇到过这个错误。我怎样才能算出来呢?由于

我通过在sdk名称中给出结构来解决这个问题。如下:

:

typedef struct
{
int isOpen;
int clearAll;
int clearSome;
int buttonFifty = -1;
int buttonTwenty = -1;
}

:后

typedef struct a
{
int isOpen;
int clearAll;
int clearSome;
int buttonFifty = -1;
int buttonTwenty = -1;
}

作为微软文档,您的struct没有名称,但在一个类型定义内与一些成员在行中初始化。下面的代码在VS 2022

中可以正常编译
typedef struct 
{
int isOpen;
int clearAll;
int clearSome;
int buttonFifty;// = -1;
int buttonTwenty;// = -1;
}ALL_Buttons;
int main()
{
return 0;
}

编译器根据不同的c++版本发出警告或错误。

最新更新