使用std :: vector

时间:2016-11-10 16:41:12

标签: c++ stl gmp mpfr

我希望有一个类作为mpfr_t元素的矩阵。我认为STL Vectors对于动态分配尽可能多的这些来说是一个好主意,但我在这里遇到了一些错误。

#ifndef GMPMATRIX_H
#define GMPMATRIX_H

#include <vector>
#include <mpfr.h>

typedef std::vector<mpfr_t> mpVector;
typedef std::vector<mpVector> mpMatrix;

class GmpMatrix
{
    private:
        int n;
        int m;
        mpMatrix elements;

    public:
        GmpMatrix() {}
        GmpMatrix(int n, int m)
        {
            this->n = n;
            this->m = m;

            for (int i = 0; i < n; ++i)
            {
                mpVector e_push(m);
                for (int j = 0; j < m; ++j)
                {
                    mpfr_t e;
                    mpfr_init(e);
                    e_push.push_back(e);
                }
            }
        }


        ~GmpMatrix() {}
};

#endif // GMPMATRIX_H

错误是:

   /usr/include/c++/5/ext/new_allocator.h:120:4: error: parenthesized initializer in array new [-fpermissive]
      { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
        ^
    /usr/include/c++/5/ext/new_allocator.h:120:4: error: no matching function for call to ‘__mpfr_struct::__mpfr_struct(const __mpfr_struct [1])’

我真的很关注这一点,我无法弄明白。有没有办法使vector< vector<mpfr_t> >工作?有谁知道发生了什么?

1 个答案:

答案 0 :(得分:0)

mpfr_t是一种C风格的数组类型。您无法将其存储在std::vector

您可以将mpfr_t包裹在一个简单的struct中并存储它们。

相关问题