Puzzle 16An Overloaded Container

 #include <initializer_list>
 #include <iostream>
 
 struct​ Container
 {
  Container(​int​, ​int​)
  {
  std::cout << ​"Two ints​​\n​​"​;
  }
  Container(std::initializer_list<​float​>)
  {
  std::cout << ​"std::initializer_list<float>​​\n​​"​;
  }
 };
 
 int​ ​main​()
 {
  Container container1(1, 2);
  Container container2{1, 2};
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

The program displays the following output:

 Two ints
 std::initializer_list<float> ...

Get C++ Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.