从std :: unique_ptr数组获取原始指针数组 [英] Get array of raw pointers from array of std::unique_ptr

查看:255
本文介绍了从std :: unique_ptr数组获取原始指针数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个库函数,需要四个指针数组作为参数: f(unsigned char * data [4]),并且我的代码中有一个智能指针数组: std :: unique_ptr< unsigned char>myArray [4] .

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 ?

我已经尝试过了,但是它给了我一个段错误: f(reinterpret_cast< unsigned char **>(myArray [0] .get()));

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

推荐答案

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

通过 arr.data().

这篇关于从std :: unique_ptr数组获取原始指针数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆