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

标签 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 *array = which_one ? array2 : array1; 

或者

  uint_fast8_t *array[] = {which_one ? &array2 : &array1}

关于c++ - 使用 if (? operator) 语句传递带指针的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56466072/

相关文章:

c++ - 在 Qt 中获取原始鼠标移动

c++ - C/C++ 中 char *(字符指针)的大小会有所不同吗? - 用于数据库列固定大小

c++ - 防止为非常量对象调用 const 函数

c++ - 在 vector 中存储基于 CRTP 的类时遇到问题

c++ - 用mysql原生函数进行字节序转换

c++ - 迭代器重载成员选择与间接运算符

c++ - LNK2019, boost::asio

c++ - 如何使路径适应每个人的计算机

c++ - Gcc,使用 no_caller_saved_registers 属性

c++ - 无法在qt之外运行应用程序