Question 20
Back to Exercise
A class has Bag(int n, int v) and Bag(std::initializer_list<int>). Which runs for Bag b{3, 7};?
- A Bag(int, int)
- B Bag(std::initializer_list<int>) Correct
- C Neither – ambiguous
- D The default constructor
Correct Answer: Option B
Brace initialization strongly prefers an initializer_list constructor when one can be used. Bag b(3, 7); calls the two-int constructor – the same reason std::vector<int>{3, 7} differs from (3, 7).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!