DEV Community

Discussion on: What's the Wackiest Coding Hack You've Ever Seen?

Collapse
 
tandrieu profile image
Thibaut Andrieu
#define private public
#include <SomeClassWithPrivateMembers.h>
Enter fullscreen mode Exit fullscreen mode

For those who are not familiar with C++, the #define private public say that "Starting from now, each time you see “private” word, replace it with “public”.

Meaning, you can now access private members of following class.
I had to do this to workaround an uninitialized private variable in a 3rd part, leading to a crash.
Definitely an anti-pattern and doesn't work every time (create some low level binary incompatibilities).