0

I don't know why this program goes wrong, because it is simple; however, if I can't use vector in GMP, the task will be so hard.

This is my code:

vector<mpz_t> elements;
  cout << elements.size() << endl;
  mpz_t a;
  mpz_init(a);
  elements.push_back(a);

This works well, but it is not as useful as vector:

// mpz_t b[10];
  // for (int i = 0; i < 10; i++){
  //   mpz_init(b[i]);
  // }

enter image description here

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83

1 Answers1

1

mpz_t is a typedef to an array type. Instead of a vector of mpz_t, in C++ I would advise to either encapsulate mpz_t in your own class (that will also allow to manage memory) or use a vector of pointers to mpz_t.

As for the first option, it already exists in the name of mpz_class.

why i can't use vector with mpz_t in gmp?

mpz_t is a typedef to an array type. (From the answer of this question): arrays are not copy constructible and not assignable, so you can't do std::vector<int[1]>.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111