[Solved] Square matrix use
-
From the main of my application I have instantiated a 2D square array/matrix (constant 10x10 dimensions) which I'd like to pass to a Tools class that can read, write save_to_file or read_from_file the different states of that matrix.For example to change the matrix[2][5] = 1 ->2 or be able to save the whole matrix to a file.
Therefore, I've thought that QGenericMatrix may be appropriated :
@QGenericMatrix<10,10,int> MyMatrix;@
to call it with all the methods in _tools _ class like :
@Tools::write_matrix(unsigned short i, unsigned short j, unsigned short value)@
My question is then :
How to be able to call these methods with the matrix instantiation from the main ?
while it's declared as :
@QGenericMatrix::QGenericMatrix(const QGenericMatrix<N, M, T> & other)@
-
Hi,
You can either typedef your matrix type
@typedef QGenericMatrix<10, 10, int> MyCoolMatrix@
Or use const QGenericMatrix<10, 10, int> &matrix as parameter of your function.
Hope it helps
-
Hi,
You can't access the main function scope in other classes (normal way)
it's better to pass matrix as one of your function parameters
or
put your tools function members in Matrix classes by inherit and after define or overload your functions. :) -
If I'd go with your point of view Jafar I would declare the matrix within the tools class and have just to send coordinates and value from the main as I exposed but write it from within the Tools itself.
Sometimes I wonder why looking in complicated ways when a simple solution is fine, ie : Occam's razor.Thanks to both of you.