0

QT4.7 と MPIR ライブラリ (v. 2.3.1) を使用して C++ でプログラムを作成しようとしています。いくつかの計算中に、動的な量の mpz_t (整数ストレージ タイプ) を格納する必要があり、そのために QList または QVarLengthArray を使用したいと考えています。私はそれを行う方法に関する基本的なテストを正常にセットアップしましたが、これは非常に見苦しく、明らかに間違っているように見えるので、これを行うためのより良い方法を求めたいと思います.

私のサンプルプログラム:

#include <QtCore/QCoreApplication>
#include <QList>
#include <qtimer.h>
#include <mpirxx.h>
#include <iostream>

int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);
    QList<__mpz_struct> test;

    std::cout << "Write ints 0 to 9 in the QList" << std::endl;

    for (int i = 0; i < 10; ++i) {
        mpz_t zahl;
        mpz_init_set_si(zahl, i);
        test.append(zahl[0]);
    }

    std::cout << "Check if everything is still there." << std::endl;

    for (int i = 0; i < 10; ++i) {
        mpz_t zahl;
        zahl[0] = test.at(i);
        std::cout << mpz_get_str(NULL, 10, zahl) << std::endl;  
    }
    std::cout << "What an ugly hack." << std::endl;

    QTimer::singleShot(0, &a, SLOT(quit()));
    return a.exec();
}

(Windows 7/MSVC2010 SP1/QT4.7.3/MPIR2.3.1 でコンパイル) 出力は正しいですが、mpz_t を格納する有効な方法または安全な方法でさえあるとは思えません。

これを達成する方法を教えてください:)

4

1 に答える 1