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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -