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  

This is a 2D vector, it should be something like this:

  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

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -