0

I'm trying to hold polynomial coefficients in QVector. My polynomials are of degree 2, so it has three numbers.

When I define QVector<double[3]> zeros_Real(n + 1) I get an error (below). First, I thought I could use QVector<QVector<double>> but it will be speed and memory problem, so I decided to not do that.

Why can't I have a QVector of double[3] elements?

The error:

mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make: *** [debug] Error 2
21:27:01: The process "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project untitled11 (kit: Desktop Qt 5.5.1 MinGW 32bit)
When executing step "Make"
LogicStuff
  • 19,397
  • 6
  • 54
  • 74
massaimara98
  • 7,401
  • 1
  • 18
  • 18

1 Answers1

5

QVector (like std::vector) requires its elements to be copyable (it has to copy the elements during reallocation). Arrays can not be copied, that implies you can't have QVector<double[3]>.

The working alternative is to use std::array (C++11 or later):

QVector<std::array<double, 3>>

Which can be copied. Qt doesn't have its own QArray, so you have to mix the standard library and Qt containers like this.

LogicStuff
  • 19,397
  • 6
  • 54
  • 74
  • your answer is awesome, but i cant call array or std::array , which i defined using namespace std and include array library already. – massaimara98 Dec 22 '15 at 19:58
  • What's the error? Are you compiling it as C++11 or later? – LogicStuff Dec 22 '15 at 19:59
  • there isnt any error, just i cant call ,i mean not coming from CTRL+Space . i'm using Qt Creater 3.5.1 and Qt version 5.5.1 which i dont know which C++ version compiler is ? – massaimara98 Dec 22 '15 at 20:02
  • I don't know what that shortcut does in Qt Creator, if your program doesn't start in an IDE, the most common reason is that it didn't compile. You should be able to see something. – LogicStuff Dec 22 '15 at 20:04
  • now when i compile it ,i get this error C:\Qt\Tools\mingw492_32\i686-w64-mingw32\include\c++\bits\c++0x_warning.h:32: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \ ^ – massaimara98 Dec 22 '15 at 20:06
  • 1
    That's what I was thinking. See [this](http://stackoverflow.com/questions/16948382/how-to-enable-c11-in-qt-creator). – LogicStuff Dec 22 '15 at 20:07