One explain on initializing each vector argument.. please

one outright understand definitely each vector argument in initialization (v) ?

enum Mon : int {
A = 5,
B, C
};

struct M {

explicit M(Mon m, Mon n) : v{ 1, m } {}
vector<Mon> v;
};


int main(){
Mon m=A, n=B;

M moo{m, n};

}
When posting code, please use code tags so that the code is readable


[code]
//formatted code goes here
[/code]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <vector>
#include <iostream>

enum Mon : int { A = 5, B, C };

struct M {
	explicit M(Mon m, Mon n) : v { 1, m } {}
	std::vector<Mon> v;
};

int main() {
	Mon m = A, n = B;

	M moo { m, n };

	for (const auto& m : moo.v)
		std::cout << m << ' ';

	std::cout << '\n';
}


If you run this code you'll get:


5


as L7 initialises v with 1 item of value m which is A which is 5. Hence the one item output of 5.

Which for the vector reference given above is (3).
Topic archived. No new replies allowed.