I am using Unreal Engine 4 with some external .dll libraries. I have encountered a problem where "PI" is defined in unreal engine core code as "3.141592..." like this:
#define PI (3.1415926535897932f)
However, in the header file supplied with the .dll library I am using, "PI" is the name of a protected member variable of a class:
protected:
SomeDataType PI;
I cant edit the define because it is used in the core files of the Unreal Engine. I believe I can not edit the header file as well as it would no longer match the underlying .dll.
Is there a good solution for this? Can I undefine "PI" locally or something?
This is a problem with macros, and is the reason why modern C++ programmers try to avoid them as much as possible.
One solution is for your code to not include the Unreal header file directly, but make up something like:
// my_unreal.h
#include "unreal.h"
#undef PI
And then in the rest of your code only do #include "my_unreal.h"
, and not the actual unreal header. So that the macro is gone by the time any other code happens.