错误:'class'之前的预期unqualified-id

时间:2017-10-22 23:06:20

标签: c++ x11

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

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

当我尝试编译时,我得到了下面给出的错误:

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

现在我该怎么做才能使它有效?!!

1 个答案:

答案 0 :(得分:2)

以下是来自/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会员名称。