Reputation: 461
Using gmp, I declare:
mpz_class x = 0;
but now if I want to use x as an index of an array, like so:
textArray[x];
I get this error "error: no match for 'operator[]' in 'testArray[x]'"
So how do I get around this?
Upvotes: 2
Views: 4929
Reputation: 105876
The usual operator[]
takes a size_t
. You need to convert your mpz_class
instance in a compatible type:
textArray[x.get_ui()];
Note that this will lead to trouble if x
is greater than std::numeric_limits<unsigned long>::max()
(check with x.fits_ulong_p())
. Note that mpz_class
is also most-likely not very well suited for that task. Ask yourself: should an index be arbitrary large?
See also:
Upvotes: 11