R
Richard Cavell
Hi,
I want to create an arbitrary number of objects, whose size will vary.
I want to keep track of them. It seems best to create an array of
pointers to these objects. Since the array itself will have its size
determined at runtime (since I don't know how many objects), I want to
dynamically allocate the array and have a pointer to the array. The
objects in question are GMP large integers.
#include <gmp.h> // mpz_t is defined.
int i;
mpz_t** pp_bigints;
pp_bigints = new mpz_t*[NumberOfMPZNeeded];
for (i=0; i<=NumberOfMPZNeeded ;i++)
{
mpz_t* p_bigint = new mpz_t;
// This fails: cannot convert __mpz_struct* to __mpz_struct (*)[1]
}
for (i=0; i<=NumberOfMPZNeeded;i++)
delete pp_bigints;
delete[] pp_bigints;
Then I need to dereference pp_bigints, then fill array slot i with
p_bigint, and assign a created mpz_t to what it points to.
Is there a better way?
I want to create an arbitrary number of objects, whose size will vary.
I want to keep track of them. It seems best to create an array of
pointers to these objects. Since the array itself will have its size
determined at runtime (since I don't know how many objects), I want to
dynamically allocate the array and have a pointer to the array. The
objects in question are GMP large integers.
#include <gmp.h> // mpz_t is defined.
int i;
mpz_t** pp_bigints;
pp_bigints = new mpz_t*[NumberOfMPZNeeded];
for (i=0; i<=NumberOfMPZNeeded ;i++)
{
mpz_t* p_bigint = new mpz_t;
// This fails: cannot convert __mpz_struct* to __mpz_struct (*)[1]
}
for (i=0; i<=NumberOfMPZNeeded;i++)
delete pp_bigints;
delete[] pp_bigints;
Then I need to dereference pp_bigints, then fill array slot i with
p_bigint, and assign a created mpz_t to what it points to.
Is there a better way?