Initializing two-dimensional vector of type Class

Hello,
I have one question. When I was using int as type of my vector I initialized it the way you can see below. But now, I want to create vector of type Values but I don't know how to initialize it. How can I do so?
Thanks for your answers.
1
2
3
4
5
6
7
  class Values {
public:
	int value = 0;
	bool added = false;
};

vector< vector<int> > board{ { 0,0,0,0 },{ 0,0,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } };
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# include <iostream>
# include <vector>
# include <iomanip>

class Values {
public:
	int value = 0;
	bool added = false;
};

int main()
{
    std::vector<std::vector<Values>> board(4, std::vector<Values>(4));

    for (const auto& elemOuter : board)//sanity-check
    {
        for (const auto& elemInner : elemOuter)
        {
            std::cout << elemInner.value << " " << std::boolalpha << elemInner.added << " | ";
        }
        std::cout << "\n";
    }

}

https://stackoverflow.com/questions/17663186/initializing-a-two-dimensional-stdvector
Last edited on
Topic archived. No new replies allowed.