samedi 21 février 2015

Dynamic bigint array in GMP

I'm using GMP or MPZ bigint library in my C++ code. I need to know how I can create a dynamic array of bigint. What I did is something like:


TBN: mpz_t is how we define an object of big integer



class A{
...
mpz_t *val;
B();
A(int n){mpz_init(val[n]);
...
}


A::B(){
int n=10;
mpz_t f[n];
for(int i=0;i<10;i++){
mpz_init_set_str(f[i],"something_i",10)
mpz_init_set(val[i],f[i]);}
}


int main(){
A a(5);
cout<<a.val[1]<<" "<<a.val[2]<<" "<<endl;
}


But I get "Segmentation fault (core dumped)" error (I use cygwin as a compiler)


So y question is:"How can I define a dynamic array for mpz_t type values?


Aucun commentaire:

Enregistrer un commentaire