简体   繁体   English

声明SystemC类型sc_fix的向量

[英]Declare vector of SystemC type sc_fix

I am trying to make a std::vector of type sc_fix . 我正在尝试使类型为sc_fixstd::vector I know that I can make std::vector<sc_fixed<WL,IWL, ...>> name; 我知道我可以使std::vector<sc_fixed<WL,IWL, ...>> name; . However I would like to use the non-template version sc_fixed . 但是,我想使用非模板版本sc_fixed However I am not sure how to instantiate this vector and set the word and integer bit lengths as I can not declare it the same was as the templated version. 但是我不确定如何实例化此向量并设置字和整数位的长度,因为我无法声明它与模板化版本相同。

I have tried making an array to fill in a memory space of the same type, but this gives me an error as well. 我试图制作一个数组来填充相同类型的内存空间,但这也给我一个错误。

sc_fix* img_num (32, 15, SC_RND_ZERO, SC_SAT_ZERO);
img_num[0] = 12.12;
img_num[1] = 12.12;
img_num[2] = 12.12;
img_num[3] = 12.12;
std::vector<sc_fix> img (img_num, img_num+sizeof(img_num) / sizeof(img_num[0]));

This gives me the error 这给我错误

Main_Test.cpp: In function ‘int sc_main(int, char**)’:
Main_Test.cpp:24: error: initializer expression list treated as compound expression
Main_Test.cpp:24: error: cannot convert ‘sc_dt::sc_o_mode’ to ‘sc_dt::sc_fix*’ in initialization
make: *** [Main_Test] Error 1

What is causing this error and how can I fix it? 是什么导致此错误,我该如何解决?

You have to remove the * after sc_fix do declare a variable of type sc_fix , not pointer-to sc_fix* , and call it's constructor: 你必须删除*sc_fix做声明类型的变量sc_fix ,不是指针到sc_fix* ,并调用它的构造函数:

sc_fix img_num (32, 15, SC_RND_ZERO, SC_SAT_ZERO);

The compiler tried to initialize a pointer and complained about the too many initializes provided. 编译器尝试初始化指针,并抱怨提供的初始化太多。

But I think what you want to do is allocate vector with 4 numbers: 但是我认为您想要做的是分配具有4个数字的向量:

std::vector<sc_fix> img_num (4, sc_fix(32, 15, SC_RND_ZERO, SC_SAT_ZERO));
img_num[0] = 12.12;
img_num[1] = 12.12;
img_num[2] = 12.12;
img_num[3] = 12.12;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM