ProgrammingVery hardProduct-company placement · C++
What is printed?
What is printed?
struct W {
W(int, int) { cout << "2"; }
W(initializer_list<int>) { cout << "L"; }
};
int main() { W a(1, 2); W b{1, 2}; }- A. 22
- B. 2L
- C. LL
- D. L2
Correct answer: B. 2L
With braces, a constructor taking initializer_list is strongly preferred whenever it is viable; parentheses use ordinary overload resolution and pick W(int, int).
More OOP with C++ and Java questions
- Two classes hold sharedptr members pointing to each other (a parent owns its child and the child owns its parent). What happens when the…
- OrderService creates new MySqlRepository() inside its own constructor. It is refactored to receive a Repository interface through its…
- An interface Machine declares print(), scan() and fax(). A SimplePrinter class implements it and has to make scan() and fax() throw…
- A GUI toolkit must create a matching Button, Checkbox and Window for either a Windows or a Mac theme, guaranteeing that all widgets come…
- In C++11 and later, which statement about this 'Meyers singleton' is correct? cpp Logger& instance() { static Logger log; return log; }
- How many of these are resolved at COMPILE time in C++? (i) Which function body a call to a non-virtual member function through a…