c++ - C2039 : 'Method' +W is not a member of Class

标签 c++ qt class methods

在我的项目中,我声明了一个名为 ReplaceFile 的函数,但是在我的 cpp 中引用它时,我收到了最奇怪的错误。它在我编写的方法末尾附加了一个“W”。

enter image description here

它到底为什么会认为我写了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 函数一样,它有两种变体:

  1. ReplaceFileW 用于宽字符串
  2. ReplaceFileA(用于 ASCII 字符串)

使用哪一个取决于UNICODE宏。问题在于:符号 ReplaceFile 只是一个预处理器宏,它根据情况扩展为 ReplaceFileWReplaceFileA 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/

相关文章:

c++ - 逐字串化

c++ - 在 Windows 上安装 C/C++ 库

c++ - 带有预告片的可变大小结构

c++ - 如何访问来自不同类的变量?

c++ - 制作一个可滚动的小部件区域

c++ - Qt qrc 资源文件 - 无法加载图标

Qt postEvent() 和事件过滤器

c++ - 我应该上课而不是重复的 get/set 语句吗?

css - 为什么导航类名称是 navbar-default 而不是 navbar

java - 创建新类对象时出现另一个 'cannot find symbol' 错误