在我的项目中,我声明了一个名为 ReplaceFile 的函数,但是在我的 cpp 中引用它时,我收到了最奇怪的错误。它在我编写的方法末尾附加了一个“W”。
它到底为什么会认为我写了ReplaceFileW?我已经对 ReplaceFileW 进行了项目搜索,但一无所获。
如果您需要任何其他内容,请发表评论,否则,这是一个简单的修复吗?
这是 ReplaceFile header 中的声明及其重载:
// Description: replace an existing file into the package
void ReplaceFile(std::string path, std::string pathInPackage, void(*replaceProgress)(void*, DWORD,
DWORD) = NULL, void *arg = NULL);
// Description: replace an existing file into the package
void ReplaceFile(std::string path, StfsFileEntry *entry, std::string pathInPackage,
void(*replaceProgress)(void*, DWORD, DWORD) = NULL, void *arg = NULL);
感谢您的宝贵时间。
最佳答案
这是因为Windows函数ReplaceFile
。与几乎所有 WINAPI 函数一样,它有两种变体:
ReplaceFileW
用于宽字符串ReplaceFileA
(用于 ASCII 字符串)
使用哪一个取决于UNICODE
宏。问题在于:符号 ReplaceFile
只是一个预处理器宏,它根据情况扩展为 ReplaceFileW
或 ReplaceFileA
UNICODE
宏。与所有宏一样,它会无条件扩展。
解决方案:在包含 Windows 系统头文件后取消定义 ReplaceFile
宏:
#include <windows.h>
#undef ReplaceFile
关于c++ - C2039 : 'Method' +W is not a member of Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38784294/