C++ 指向数组指针的指针

C++ pointer to pointer of array

如何将数组传递给此函数?

这是函数:

void fire(const uint8_t *const s[])
{
cout<<*s<<endl;
}

我想将这个数组传递给那个:

unsigned char X[10] = {255,255,255,255};

这是通过它完成的并且有效

unsigned char X[5] = {255,255,255,255};
unsigned char *pointertoX ;
pointertoX = X;
fire(&pointertoX);

为什么我需要 *pointertoX ? 还有其他方法吗?

完整代码:

#include <iostream>
using namespace std;


void fire(const uint8_t *const s[])
{
cout<<*s<<endl;
}


int main() {


unsigned char X[10] = {255,255,255,255};
unsigned char *pointertoX ;
pointertoX = X;
fire(&pointertoX);


    return 0;
}

注意:我正在尝试将位图传递给 ffmpeg "sws_scale" ..

https://ffmpeg.org/doxygen/4.1/group__libsws.html#gae531c9754c9205d90ad6800015046d74

this is the function :

void fire(const uint8_t *const s[])

该函数接受指向 const 的指针,指向 const uint8_t

and I want to pass this array to that :

 unsigned char X[10] = {255,255,255,255};

你不能。

为了将数组传递给接受指针的函数,该函数必须接受指向该数组元素类型的指针(在其他隐式转换之后,例如从非 const 指针到 const 指针).该数组的元素是 unsigned char,而函数接受指向 const 的指针,指向 const uint8_t.

why I need *pointertoX ?

因为函数接受一个指向const的指针指向一个const uint8_t,而&pointertoX是一个指向unsigned char的指针。鉴于 uint8_tunsigned char 的别名,&pointertoX 可隐式转换为函数参数。


note : I'm trying to pass bitmap to ffmpeg "sws_scale" ..

仔细阅读文档:

srcSlice the array containing the pointers to the planes of the source slice

dst the array containing the pointers to the planes of the destination image

您正试图将一个字符数组传递给一个需要指针数组的函数。


P.S。该程序的行为是未定义的,因为 *s 没有指向空终止字符串,但是您将它插入到具有这种要求的字符流中。