Question 1
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <utility>
struct W {
W() = default;
W(const W&) { std::cout << "C"; }
W(W&&) noexcept { std::cout << "M"; }
};
W make() { return W(); }
int main() {
W a;
W b(a);
W c(std::move(a));
W d(make());
W e(std::move(b));
std::cout << '\n';
return 0;
}
- A CMM Correct
- B CMMM
- C CCMM
- D CMCM
Correct Answer: Option A
b copies a, c and e are moves. d is built directly from the prvalue returned by make() – guaranteed elision, so nothing is printed.
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!