“memcpy”未定义在此范围内
我收到“memcpy 在此范围内未定义错误”,代码如下:
CommonSessionMessage::CommonSessionMessage(const char* data, int size)
: m_data(new char[size]) {
memcpy(m_data.get(), data, size);
}
我浏览了此网站和谷歌,但找不到可以为我解决问题的解决方案。
任何帮助将不胜感激。
谢谢。
I am getting a "memcpy is not defined in this scope error" with the following piece of code:
CommonSessionMessage::CommonSessionMessage(const char* data, int size)
: m_data(new char[size]) {
memcpy(m_data.get(), data, size);
}
I have looked through this site and google and could not find a solution that would resolve the issue for me.
Any assistance would be appreciated.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否在代码文件的开头包含 string.h/cstring (或包含它的另一个标头)?
Did you include string.h/cstring (or another header that includes it) at the beginning of your code file?
看来
m_data
是char*
类型。如果是这样,那么它就没有get()
函数,并且代码中的m_data.get()
就没有意义。另一种解决方案是使用 std::copy 作为:
我更喜欢第二种解决方案。阅读
std::copy
的文档。It seems that
m_data
ischar*
type. If so, then it doesn't haveget()
function, andm_data.get()
in your code wouldn't make sense.An alternative solution would be using
std::copy
as :I would prefer the second solution. Read the documentation of
std::copy
.即使包含所有正确的路径,我也遇到同样的问题(在头文件中)。原来我的文件名没有扩展名。将其从“array”重命名为“array.hpp”解决了我的问题。愚蠢的错误...很容易修复。
(我在 Mac OS X 10.6.8 上运行 Eclipse 版本:Juno Service Release 1,内部版本号:20120920-0800)
I was having this same problem (in a header file), even with all of the correct paths included. Turned out that my file name didn't have an extension. Renaming it from "array" to "array.hpp" solved the problem for me. Silly mistake...easy fix.
(I'm running Eclipse Version: Juno Service Release 1, Build id: 20120920-0800 on Mac OS X 10.6.8)