I need help in something really simple, which C++ makes very difficult. I created a class, lattice, with the aim to initialize and treat a matrix. There are the following private members:
private unsigned dim;
private double matrix [dim][dim];
I would like to initialize the variable dim in the constructor of the class through a parameter, but the compiler continue to return errors. I tried to make dim public and static and initializing it in the main program, but there are still problems. How could I create this simple class?
Moreover, I also implemented some methods in the class in order to update the values of the matrix. Is it true that, initializing an object of the class in a main program and then using its “updating” methods, the values of the matrix are stored only once?
Thank you for your help.
There are (at least) three ways to create such a class:
with a
templatewith the use of built in types such as
std::vector(e.g.valarraywould work too)with the use of plain arrays (I do not recommend that!)