Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

array bound is not an integer constant before ']' token

$
0
0
Hi everyone, I’ve been running into a little problem now, and I don’t know how to get out of it. I’m quite a beginner with QT and c++, and I’ve searched many forums but still haven’t found what I’m looking for. The idea of this code is to access an element of a velocity-matrix (u, v, and w respectively). I try to prebuild this matrix with ‘fillmatrix’ and then try to access an element using ‘getMatrixElement’. Now I’ve run into this error (see title) and though I know you need to predefine arrays, I don’t know how to get my code to work. Who can help me? The error is at lines 18-20 in the header file (where the 3 matrices/arrays are declared) The main code is: #include <cumatrix.h> #include <iostream> using namespace std;   int main() {     char u = 'u';     cuMatrix Z;     float x= Z.getMatrixElement(u,2,4);       cout<<x<<endl;     system("pause");     return 0; } header file cumatrix.h : #ifndef CLASSES_H #define CUMATRIX_H   class cuMatrix { public:       cuMatrix(void);//constructor     ~cuMatrix(void);       int setsize(int newSize);       float getMatrixElement(char letter,int i,int j);   private:       static int size;     float    u_matrix[size][size],              v_matrix[size][size],              w_matrix[size][size]; // declare u,v,w-matrices       void fillMatrices(int size);     };   #endif // CUMATRIX_H The source file cumatrix.cpp #include <cumatrix.h>   cuMatrix::cuMatrix(void) {     setsize(16); //default size     fillMatrices(size); }   cuMatrix::~cuMatrix(void) {   }   int cuMatrix::setsize(int newSize) {     size=newSize; }   void cuMatrix::fillMatrices(int size) {     for(int i=0;i<size;i++)     {         for(int j=0;j<size;j++)         {             u_matrix[i][j]=2*i+3*j*j; //fill u-matrix             v_matrix[i][j]=5*i+0.2*j; //fill v-matrix             w_matrix[i][j]=-i*i+j*j; // fill w-matrix (vorticity)         }     } }   float cuMatrix::getMatrixElement(char letter, int i, int j) {       float element;     switch(letter)     {     case 'u':         element=u_matrix[i][j];     case 'v':         element=v_matrix[i][j];     case 'w':         element=w_matrix[i][j];     }     return element; }

Viewing all articles
Browse latest Browse all 13965

Trending Articles