错误:“类”之前应为非限定 ID

error: expected unqualified-id before ‘class’

本文关键字:ID 错误      更新时间:2023-10-16

在XVisualInfo结构中,有一个名为class的属性,当我想在c ++程序中使用此结构时,会出现此问题:

...
XVisualInfo templ;
templ.screen = screen;
templ.depth = 32;
templ.class = TrueColor;
...

当我尝试编译时,我得到以下错误:

error: expected unqualified-id before ‘class’
templ.class = TrueColor;
      ^~~~~

现在我能做些什么来让它工作?!!

这是

来自/usr/include/X11/Xutil.h的XVisualInfo的实际定义

typedef struct {
  Visual *visual;
  VisualID visualid;
  int screen;
  int depth;
#if defined(__cplusplus) || defined(c_plusplus)
  int c_class;                  /* C++ */
#else
  int class;
#endif
  unsigned long red_mask;
  unsigned long green_mask;
  unsigned long blue_mask;
  int colormap_size;
  int bits_per_rgb;
} XVisualInfo;

如您所见,编写C++代码的规定就在那里。只需使用c_class成员名称。