Reputation: 1143
I am trying to make a std::vector
of type sc_fix
. I know that I can make std::vector<sc_fixed<WL,IWL, ...>> name;
. However I would like to use the non-template version 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?
Upvotes: 1
Views: 898
Reputation: 3911
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 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:
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;
Upvotes: 2