Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 gmp,我声明:
mpz_class x = 0;
但现在如果我想使用 x 作为数组的索引,如下所示:
textArray[x];
我收到此错误“错误:'testArray [x]'中的'operator []'不匹配”
那么我该如何解决呢?
通常operator[]需要一个size_t. 您需要将您的mpz_class实例转换为兼容的类型:
operator[]
size_t
mpz_class
textArray[x.get_ui()];
x请注意,如果大于std::numeric_limits<unsigned long>::max()(检查) ,这将导致麻烦x.fits_ulong_p())。请注意,这mpz_class也很可能不太适合该任务。问问自己:索引应该任意大吗?
x
std::numeric_limits<unsigned long>::max()
x.fits_ulong_p())
也可以看看: