C++ 错误 C2039:“memchr”:不是“全局命名空间”的成员

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/531916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:49:49  来源:igfitidea点击:

error C2039: 'memchr' : is not a member of '`global namespace''

c++

提问by Autodidact

It has been quite a while since I am getting this error in the standard <cstring> header file for no apparent reason. A google search brought up many answers but none of them worked.

自从我无缘无故地在标准 <cstring> 头文件中收到此错误以来,已经有一段时间了。谷歌搜索带来了许多答案,但没有一个奏效。

回答by Autodidact

Ok I fixed it myself. It was a stupid mistake! I have a file called "String.h" in a library project which is being picked up by the <cstring> header. Probably because I have added the path to <String.h> as an additional include directory in my test project (where I am getting this error.) Hope this helps someone.

好的,我自己修好了。这是一个愚蠢的错误!我在一个库项目中有一个名为“String.h”的文件,该文件由 <cstring> 标头获取。可能是因为我已经将 <String.h> 的路径添加为我的测试项目中的附加包含目录(我在那里收到此错误。)希望这对某人有所帮助。

回答by Autodidact

Your compiler may be (correctly) placing the memchr function in the C++ std namespace. Try prefixing memchr call with std:: and if that fails, post the code that causes the problem.

您的编译器可能(正确)将 memchr 函数放置在 C++ std 命名空间中。尝试使用 std:: 为 memchr 调用添加前缀,如果失败,请发布导致问题的代码。

回答by Autodidact

Preprocessor defines are pretty handy when you want to avoid this sort of mistake.

当您想避免此类错误时,预处理器定义非常方便。

//whatev.h
#ifndef WHATEV
#define WHATEV

// your code here

#endif