I am writing a program organized in some classes divided into some files.
In file gpa.h and gpa.cpp is the declaration of class gpa. In file gpa.h I did:
static vector<vector<double> > matrix;
The above line is outside any class declaration.
There is another file/class LoadFile, this class have a method getmatrix. In fact getmatrix load a matrix inside matrix(declared in gpa.h).
The problem is that I need to setup the size of matrix, for that, before store the values in matrix I create another matrix mx and copy that one into matrix:
You can use pointers to vectors, but that sort of defeats the purpose of using a vector. Vectors are meant to be as a means to store dynamic data and it's job is to manage how that data is stored. So you should give it a size that should suit your needs and it will resize its internal array if it needs to. Since you know the size of the matrix at execution time, assuming it's not going to change often, what's stopping you from using a pointer to an array of pointers to arrays?