c++struct

using a struct with element name new in c++


I want to use the XColormapEvent structure in c++.

It is defined as

typedef struct {
int type;
unsigned long serial;
Bool send_event;
Display *display;
Window window;
Colormap colormap;
Bool new;
int state;
} XColormapEvent;

As you can see, there is an element with the name new.

Can it be accessed with c++?

Simple example:

struct Y
{
        int new;
};

int main()
{
        Y y;
        y.new=5;  // expected unqualified-id before »new« 
}

Solution

  • You should not have any problems with #include <X11/Xlib> because the struct is defined there

    typedef struct {
        int type;
        unsigned long serial;   /* # of last request processed by server */
        Bool send_event;    /* true if this came from a SendEvent request */
        Display *display;   /* Display the event was read from */
        Window window;
        Colormap colormap;  /* COLORMAP or None */
    #if defined(__cplusplus) || defined(c_plusplus)
        Bool c_new;     /* C++ */
    #else
        Bool new;
    #endif
        int state;      /* ColormapInstalled, ColormapUninstalled */
    } XColormapEvent;
    

    although all XLib manuals do not show that Bool c_new.