Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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++/SystemC:有没有办法只从数组中选择一系列值?(例如,从10个值的数组中选择5个值)_C++_Systemc - Fatal编程技术网

C++/SystemC:有没有办法只从数组中选择一系列值?(例如,从10个值的数组中选择5个值)

C++/SystemC:有没有办法只从数组中选择一系列值?(例如,从10个值的数组中选择5个值),c++,systemc,C++,Systemc,好的,这是我正在尝试的。我已将数组传递给函数。在返回时,我只想发送数组中定义的值。例如,假设我有一个10的数组定义,我只想在函数中从该数组返回5个值 有什么建议吗!?谢谢 示例代码: sc_uint<8> *arrayfill(struct){ sc_uint<8> array[10]; array[1] = struct.a; array[2] = struct.b; ... if (struct.trigger == false){ array[10] =0;

好的,这是我正在尝试的。我已将数组传递给函数。在返回时,我只想发送数组中定义的值。例如,假设我有一个10的数组定义,我只想在函数中从该数组返回5个值

有什么建议吗!?谢谢

示例代码:

sc_uint<8> *arrayfill(struct){
sc_uint<8> array[10];

array[1] = struct.a;
array[2] = struct.b;
...
if (struct.trigger == false){
  array[10] =0;
}
else 
{
  array[10] = struct.j;
}

return array;
}

现在的问题是,当struct.trigger为false时,我只想返回最多9个数组值,否则我将返回数组的所有值。这就是我找不到解决方案的地方。

我认为您可以使用数组引用作为in和out参数,从in数组中提取5个元素,然后将其放入out数组中。 比如:


当然,您也可以选择数组中的特定元素。

前五个?随便挑五个?五个符合某些标准?请出示一些代码。@Biffen:这五个代码符合随机条件。。!!!我将在下面输入一个示例代码@于浩:谢谢你的建议,但我想这可能是我答案的答案。请参考上面的代码了解我的问题。
void ExtrctElemnts(const std::vector<int>& in_array, std::vector<int>& out_array){
     for(int i = 0; i < 5; i++){
          out_array.push_back(in_array.at(i));
     }
}