unique_ptr<byte[]> and memcpy

  • Thread starter Thread starter Jy_13
  • Start date Start date
J

Jy_13

Guest
Hi,

I'm trying to use a unique_ptr<> and then use memcpy() to copy a byte array to it.

Like this:

std::unique_ptr<byte[]> pStrt = std::make_unique<byte[]>(iMaxCount);
memcpy(pStrt, &lVal, sizeof(lVal));

I'm using VS 2017.

But memcpy() gives an error saying no suitable conversion available to void *.
If I try to use static_cast<void*>(pStrt) or reinterpret_cast<void*>(pStrt), I still get an error.
My question is how do I use unique_ptr to first allocate a size of iMaxCount, and then copy the byte array into it?

TIA,
Jy

Continue reading...
 
Back
Top