我有一些C++代碼,其中包括一種稱爲CreateDirectory().
的方法此前代碼僅使用STL和Boost,但最近我不得不包含<windows.h>
,因此我可以查找CSIDL_LOCAL_APPDATA
。如何避免與Windows頭文件中定義的宏發生名稱衝突?
現在,這個代碼:
filesystem.CreateDirectory(p->Pathname()); // Actually create it...
不再編譯:
error C2039: 'CreateDirectoryA' : is not a member of ...
相當於本宏winbase.h
:
#ifdef UNICODE
#define CreateDirectory CreateDirectoryW
#else
#define CreateDirectory CreateDirectoryA
#endif // !UNICODE
預處理器重新定義了我的方法呼叫。有沒有任何可能的方法來避免這種命名衝突?或者我必須重新命名我的CreateDirectory()
方法?
現在你知道爲什麼Bjarne Stroustrup想要擺脫C預處理器 - 參見'C++的設計和演變'。 – 2010-02-23 21:09:22
可能與答案重複:http://stackoverflow.com/questions/1394910/how-to-tame-the-windows-headers-useful-defines – 2010-02-23 21:24:43
請投票:http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/6656174-have-a-version-of-windows -h-that-t-define-ma – 2014-11-04 14:10:20