An Overloaded Container

Test your C++ programming skills by solving the given puzzle about constructor overloading and initialization.

Puzzle code

Carefully read the code given below:

Press + to interact
#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};
}

Your task: Guess the output

Try to guess the output of the above code. Attempt the following quiz to assess your understanding.

Q

What is the expected output of the above code?

A)
Two ints
Two ints
B)
Two ints
std::initializer_list<float>
C)
std::initializer_list<float>
Two ints
D)
std::initializer_list<float>
std::initializer_list<float>

Let’s discuss this code and output together in the next lesson.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.