SeekHunt1334 SeekHunt1334 - 1 year ago 90
C++ Question

Dynamically Allocated mpfr_t matrix with std::vector

I want to have a class that works as a matrix of mpfr_t elements. I thought STL Vectors would be a great idea for dynamically allocating as many of these as I want, but I get some errors here.


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

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

class GmpMatrix
int n;
int m;
mpMatrix elements;

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; ++i)
mpfr_t e;

~GmpMatrix() {}

#endif // GMPMATRIX_H

The errors are:

/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])’

I've really looked into this and I can't figure it out. Is there a way to make a
vector< vector<mpfr_t> >
work? Does anyone know what is happening?

Answer Source

mpfr_t is a C-style array type. You cannot store those in std::vector.

You can wrap mpfr_t in a simple struct and store those.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download