Dear all,
first of all as I'm new in the forum Hello to everybody, I'm Luca.
Hope I'll be able to help others as well as I get confidence with C++
I'm an experienced Matlab user (+10yrs), but now I have to switch to C/C++
for some of my projects and I'm trying to learn but there are some differences
in the way of coding that sometimes make me confused.
So what I'm trying to achieve is pretty straightforward:
I have a class Node defined like this:
1 2 3 4 5 6 7 8 9
|
class Node{
private:
enum NodeTypes NT ; // the Nodetype is defined in the header file.
int lab ;
public:
Node(NodeTypes x, int l)
:NT(x), lab(l) {}
}
|
(a very simple class indeed, it just stores the type of node and a value lab associated with it. I have defined also setter and getter and other functions working on one or more Node variables.
I want to define a Grid class that contains a matrix of Nodes and other parameters (like the number of nodes on each row and the number of nodes on each column, the number of nodes of given types and so on).
In the Grid class declaration I have defined this matrix as:
NodesMat **Node ;
and I define the constructor as:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
Grid::Grid(int ny, int nx)
:nRows(ny), nColumns(nx) {
NodesMat= new Node* [ny];
for (int i=0 ; i < (ny) ; i++){
NodesMat[i] = new Node [nx];
for (int j=0; j<(nx) ; j++){
NodesMat[i][j] =Node(BasalCell,i*(nxF) + j+1) ;
}
}
}
|
Now, I'd like to know if I there are alternative implementations
that use the vector STL class.
Or if there is any better way, all the advices are greatly appreciated (actually if you can explain me the different ways that exist and when to prefer one to the other it would be instructive as well, even though it might not be the best solution in this case).
Thanks a lot in advance for the help,
Have a nice day,
Luca