Category : 2d-vector

So I am trying to initialize a 2D vector of pointers/matrix of pointers(/3d vector?) in c++. A 2D matrix of pointers to cell objects. When running the code I get this error: error: no matching function for call to ‘std::vectorstd::vector<Cell* >::push_back(std::vector&)’ 17 | matrix.push_back(temp); Note:Cell is a class City.hh: std::vector <std::vector <Cell*>> matrix; City(unsigned int ..

Read more

I am trying to create a 10 by 10 grid with uint8_t values. using some coordinates I am trying to place 255 values at those indexes. When I substitute 255 at those coordinates it works fine but as soon as I try to print out the values at those indexes it doesn’t seem to be ..

Read more

I was creating empty 2D vector in a header file by just providing size but unable to create it. class Grid { public: int rows = 5/0.05; int cols = 6/0.05; std::vector<std::vector<uint8_t>> grid(rows, std::vector<uint8_t>(cols, 0)); }; I am getting below error no matching function for call to ‘std::vector<std::vector >::vector(int&, std::vector)’ error: ‘rows’ is not a ..

Read more

I have a simple ball class. It takes a color name for its initialization. Ball::Ball(ColorName color_name) : m_color_name{color_name} { } I try to create a 2d-vector board to contain some balls. The width and the height are given outside. class Board { private: int m_width; int m_height; std::vector<std::vector<Ball>> m_grids; public: Board(int width, int height); ~Board(); ..

Read more

I am trying to take values in a 2d vector called alloc from the user but the alloc zero index is the only changed index and the values of each index override it i don’t know why (i.e: only the first index of the 2d vector is affected) Code: cout<<"Please Enter n"<<endl; cin>>n; cout<<"Please Enter ..

Read more