ProgrammingHardProduct-company placement · C++
What is printed?
What is printed?
int main() {
std::function<int()> f;
try { cout << f(); }
catch (const bad_function_call&) { cout << "E"; }
}- A. E
- B. 0
- C. Undefined behaviour: f is empty
- D. Compile-time error: f has no target
Correct answer: A. E
Calling an empty std::function is well defined: it throws std::bad_function_call.
More OOP with C++ and Java questions
- What is printed? cpp struct W { W(int, int) { cout << "2"; } W(initializerlist<int>) { cout << "L"; } }; int main() { W a(1, 2); W b{1…
- 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; }