-3
mpz_t* myArr= new mpz_t[M+1];
cout << myArr[0] << endl;
cin.get(); //so I know the program pauses here if everything's OK so far

M is a long long datatype.

I've also tried

mpz_t* myArr= new mpz_t[M+1];
mpz_set_si(myArr[0],0);
cout << myArr[0] << endl;
cin.get(); //so I know the program pauses here if everything's OK so far

Just to give it a value but it does not work still.

Runtime crash

MyNameIsKhan
  • 2,594
  • 8
  • 36
  • 56

1 Answers1

1

You have to initialize mpz_t values, which are just plain C structures with the GMP C API. If you want to use a class with constructors, use mpz_class, which is a C++ class.

Example:

mpz_class x;
x = 3;
mpz_class y;
y = x * 7;
wjl
  • 7,519
  • 2
  • 32
  • 41
  • But if I use mpz_class how can I initialize variables/perform arithmetic/etc? For example, if I want to set an mpz_class variable to x*x-1 where x is a long long – MyNameIsKhan Jun 10 '12 at 20:48
  • @Against you just assign it' e.g. `mpz_class z; z = x*x-1;`. With GMP this won't work easily with long longs and unsigned long longs because of library limitations, but will work with other built in integer types, like int, long, unsigned long, etc. – wjl Jun 10 '12 at 20:55
  • I try this in my program and it gives me more of the same "invalid operator" problems I've had when trying to force mpz's to play with non mpz's. I can't use long longs? – MyNameIsKhan Jun 10 '12 at 21:16
  • @Against Short answer: no, you cannot use long longs with GMP. Long answer: you can use long longs, but you will have to encapsulate their interaction with GMP by writing a bunch of your own code, and you will not be able to use mpz_class's operator overloading directly. – wjl Jun 10 '12 at 21:17