Hello everyone!
I've got some experience with Java and C, but I'm very new to C++. Therefore, I guess the answer to my question will be obvious, but I just can't figure it out on my own.
I've got the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <gmp.h>
#include <flint.h>
#include <fmpz.h>
#include <fmpz_poly.h>
#include <iostream>
using namespace std;
template<int length>
void random_code(fmpz_t (&result)[length]) {
for(int i=0; i<length; i++) {
fmpz_set_ui(result[i], 1); //not quite random, but for now it will do
}
}
int main() {
int len = 4;
fmpz_t test[len];
for(int i=0; i<len; i++) {
fmpz_init(test[i]);
}
random_code(test);
cout << "value of test: ";
for(int i=0; i<len; i++) {
fmpz_print(test[i]);
}
cout << endl;
return 0;
}
|
I want to initialize an array of fmpz_t's and then set each component in the array to a certain value. The problem is that I want to modify the array argument in random_code, so I made the argument a reference to that array, but it doesn't seem to work.
When I try to compile it, I get the following error and notes:
gen_code.cpp: In function 'int main()':
gen_code.cpp:23:18: error: no matching function for call to 'random_code(fmpz [len][1])'
random_code(test);
gen_code.cpp:11:6 note: candidate: template<int length> void random_code(fmpz (&)[length][1])
void random_code(fmpz_t (&result)[length]) {
gen_code.cpp:11:6: note: template argument deduction/substitution failed:
gen_code.cpp:23:18: note: variable-sized array type 'int' is not a valid template argument
random_code(test);
I know that there is something wrong with the line 'random_code(test)' in main() and that I don't call the argument correctly, but I just don't see the solution, so I hope there's someone who can help me. Thanks in advance!