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«
}
7
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
.
You cannot use new
in a c++ compiler for a member variable name, but you can
- Use a Modified header with different naming, the C ABI doesn’t care about member names.
- use the preprocessor.
#define new new_mem
#include "troublesome_header.h"
#undef new
This is not standard C++ and UB and all but it works on all compilers.
Edit: There is nothing wrong in this answer, it is only downvoted because it won’t work on the hypothetical compiler that will be written in a 100 years.
4