c++ - Initialize std::shared_ptr by copying a junk of data from a raw pointer -
basically hoping acheive:
int pbuf = {1, 2, 3, 4, 5, 6}; std::shared_ptr<int> pptr(pbuf, _arraysize(pbuf));
the following syntax invalid, possible? i'm required use shared_ptr.
if mean create copy of array pbuf
, assign std::shared_ptr
following code should work:
int pbuf[] = {1, 2, 3, 4, 5, 6}; std::shared_ptr<int> pptr( new int[_arraysize(pbuf)], std::default_delete<int[]>() ); std::copy( pbuf, pbuf + _arraysize(pbuf), pptr.get() );
Comments
Post a Comment