在 stdafx.h 包含 ximage.h 後,編譯自有文件 DrawObj.cpp 中的常量定義報錯:
const double PI = 3.14159265; // 第 24 行
// warning C4091: ignored on left of 'const double'
// error C2143: syntax error : missing ';' before 'constant'
// error C2059: syntax error : 'constant'
註釋掉 #include "ximage.h" 則正常。
ximage.h 或其依賴頭文件中可能定義了宏 PI (或其他同名標識符),導致預處理階段將 const double PI = ... 展開為 const double 3.14159... = ...,語法錯誤。
ximage.h 及其包含鏈中搜索 #define PI 或 #define PI ...。MY_PI)。ximage.h 前 #undef PI (若確定不影響 CxImage 內部邏輯)。DRAWOBJ_PI) 避免污染全局宏空間。constexpr (C++11) 或 enum 替代宏定義常量。