問題場景:此問題多發生在qt調用python.h,比如matplotlib-cpp等需要python引用的C++庫
#include <Python.h>報錯
\python\python37-32\include\object.h(448): error C2059: 語法錯誤:“;”
\python\python37-32\include\object.h(448): error C2238: 意外的標記位于“;”之前
原因: Python 和 Qt 的關鍵詞 slots 沖突
解決:
#pragma push_macro("slots")
#undef slots
#include <Python.h>
#pragma pop_macro("slots")