c++ - Passing a Vector of a Vector with variables to a function -
I was trying to create an array with the variable for size (i.e. array [x] [y]), The work that I stumbled on a post which suggests using a vector vector:
vector & lt; Vector & lt; Int & gt; & Gt; Grid (GetGridXComponent (), vector (GetGridYComponent ());
GetGridXComponent () and GetGridYComponent () receive private variables from a class.
The code works inside the function, but I need to be able to reach the vector, to class out "grid", I tried to make a public example:
vector & lt; Vector & lt; Int & gt; & Gt; Grid (GetGridXComponent (), vector (GetGridYComponent ());
But of course, GetGridXComponent () and GetGridYComponent () will not work because it thinks that I am creating a function and I want to make a type of announcement for GetGridXComponent () I am
Is there any way to go about this? Am I making this difficult by making? thank you in advanced.
Class Simulator {Private: int s_iGridXComponent; Int s_iGridYComponent; Public: Simulator (); ~ Simulator (); Int GetGridXComponent (); Int GetGridYComponent (); Zero function (vector & lt; vector & lt; int & gt; & amp;;;); Of vector & lt; Vector & lt; Integer & gt; & Gt; Tabletgrid (Getgrid XComponent (), vector (GetGridYComponent ()); } Zero simulators :: function (vector & lt; vector & gt; int & gt; & grid) {code; Assume that you are just trying to create a class member named pelletGrid
class simulator {personal: int s_iGridXComponent; Int s_iGridYComponent; Std :: vector & lt; Std :: vector & lt; Integer & gt; & Gt; PelletGrid; Public: Simulator (const int x, const int y): s_iGridXComponent (x), s_iGridYComponent (y), pelletGrid (x, std :: vector & lt; int & gt; (y)) {} barred grid grid X, const int y)) {S_iGridXComponent = x; S_iGridYComponent = y; PelletGrid = std :: vector & lt; Std :: vector & lt; Int & gt; (X, std :: vector & lt; int & gt; (wi)); }};
When you know the X / Y dimensions, you can either use constructor or custom method to start the 2D vector.
Comments
Post a Comment