Unable to create 2D vector in CPP std::vector<std::vector<uint8_t>> by just giving the size

  2d-vector, c++, class, initialization, uint8t

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 type 19 | std::vector<std::vector<uint8_t>> grid(rows, std::vector<uint8_t>(cols, 0)); | ^~~~ C:UserspraveDocumentsprojectsExhaustiveSearchScanMatchingoccupancy_grid.h:19:79: error: expected ')' before ',' token 19 | std::vector<std::vector<uint8_t>> grid(rows, std::vector<uint8_t>(cols, 0)); | ~ ^ | ) C:UserspraveDocumentsprojectsExhaustiveSearchScanMatchingoccupancy_grid.h:19:79: error: expected ')' before ',' token 19 | std::vector<std::vector<uint8_t>> grid(rows, std::vector<uint8_t>(cols, 0)); | ~ ^ | ) C:UserspraveDocumentsprojectsExhaustiveSearchScanMatchingoccupancy_grid.h:19:81: error: expected unqualified-id before numeric constant 19 | std::vector<std::vector<uint8_t>> grid(rows, std::vector<uint8_t>(cols, 0)); | ^

Can anyone please help to fix this issue.

Source: Windows Questions C++

LEAVE A COMMENT