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.
#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 char*
type. If so, then it doesn't have get()
function, and m_data.get()
in your code wouldn't make sense.
An alternative solution would be using 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 the second solution. Read the documentation of std::copy
.
Did you include string.h/cstring (or another header that includes it) at the beginning of your code file?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With