因爲你不能從一個函數返回一個自動存儲陣列,我建議你返回一個std::vector<sc_uint<8>>
來代替。它基本上只是將您的sc_uint<8>
值包裝在易於使用和移動的動態數組中。
然後簡單地push_back
您想要根據您的標準返回到vector
的值。
例如:
std::vector<sc_uint<8>> arrayfill(struct){
std::vecotr<sc_uint<8>> array;
array.reserve(10); // Reserves space for 10 elements.
array.push_back(struct.a); // This will be the first element in array, at index 0.
array.push_back(struct.b); // This will be the second element at index 1.
...
if (struct.trigger == false){
array.push_back(0);
}
else
{
array.push_back(struct.j);
}
// At this point, array will have as many elements as push_back has been called.
return array;
}
使用std::vector::insert
添加值的範圍:
array.insert(array.end(), &values[3], &values[6]);
哪裏values
是一些陣列。以上將在values
到array
的末尾插入從索引3到索引5(獨佔範圍,索引6的值不會插入)中的值。
你不能返回'array',因爲它是一個局部變量,並且會在函數結束時被銷燬。 – emlai 2015-02-09 08:57:41