Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用if(?operator)语句传递带指针的数组_C++ - Fatal编程技术网

C++ 使用if(?operator)语句传递带指针的数组

C++ 使用if(?operator)语句传递带指针的数组,c++,C++,我该怎么做 uint_fast8_t array1[100]; uint_fast8_t array2[100]; void get_a(bool which_one) { uint_fast8_t *array[] = which_one ? &array2 : &array1; //doesn't work } 这会引发一个错误,说明无法将uint_fast8_t*[100]转换为uint_fast8_t*[],因为它不是指针而是指针数组 uint_fast8_t

我该怎么做

uint_fast8_t array1[100];
uint_fast8_t array2[100];

void get_a(bool which_one)
{
uint_fast8_t *array[] = which_one ? &array2 : &array1; //doesn't work
}

这会引发一个错误,说明无法将uint_fast8_t*[100]转换为uint_fast8_t*[]

,因为它不是指针而是指针数组

   uint_fast8_t *array = which_one ? array2 : array1; 


因为它不是指针而是指针数组

   uint_fast8_t *array = which_one ? array2 : array1; 


这就解决了这个问题,但是使用指针不会让它更快吗?还是我错了?第二种方法不起作用。@FreeRenca使用指针比使用指针快多少?第二个代码段有效吗&阵列1具有uint\U fast8\U t*[100]类型。在uint\u fast8\u t*数组中不能有一个可以修复它,但是使用指针不会使它更快吗?还是我错了?第二种方法不起作用。@FreeRenca使用指针比使用指针快多少?第二个代码段有效吗&阵列1具有uint\U fast8\U t*[100]类型。uint\U fast8\U t*数组中不能有一个。是否允许使用动态分配数组?是否允许使用动态分配数组?