"memcpy" is not defined in this area

I get "memcpy not specified in this error area" with the following code snippet:

CommonSessionMessage::CommonSessionMessage(const char* data, int size) : m_data(new char[size]) { memcpy(m_data.get(), data, size); } 

I looked at this site and google and could not find a solution that would solve the problem for me.

Any help would be appreciated.

Thanks.

+6
source share
3 answers

Did you include string.h / cstring (or another header that includes it) at the beginning of your code file?

+15
source
 #include <cstring> CommonSessionMessage::CommonSessionMessage(const char* data, int size) : m_data(new char[size]) { std::memcpy(m_data, data, size); } 

It seems that m_data is of type char* . If so, then it does not have a get() function, and m_data.get() does not make sense in your code.


An alternative solution would use std::copy as:

 #include<algorithm> CommonSessionMessage::CommonSessionMessage(const char* data, int size) : m_data(new char[size]) { std::copy(data, data + size, m_data); } 

I would prefer a second solution. Read the std::copy documentation.

+2
source

I had the same problem (in the header file), even if all the correct paths are included. It turned out that my file name has no extension. Renaming it from "array" to "array.hpp" solved the problem for me. Stupid mistake ... easy to fix.

(I am running Eclipse Version: Juno Service Release 1, Build id: 20120920-0800 on Mac OS X 10.6.8)

0
source

Source: https://habr.com/ru/post/888778/


All Articles