Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get array of raw pointers from array of std::unique_ptr

I have a library function that requires an array of four pointers as parameter: f(unsigned char* data[4]), and I have an array of smart pointers in my code: std::unique_ptr<unsigned char> myArray[4].

Is there a way to use the smart pointers with this library function ?

I have already tried this but it gives me a segfault: f(reinterpret_cast<unsigned char **>(myArray[0].get()));

like image 965
James Magnus Avatar asked May 20 '26 08:05

James Magnus


1 Answers

std::array<unsigned char* , 4> arr = { myArray[0].get(),myArray[1].get(),myArray[2].get(),myArray[3].get() };

pass arr.data().

like image 84
Yakk - Adam Nevraumont Avatar answered May 22 '26 22:05

Yakk - Adam Nevraumont



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!