Question 8
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
struct Window {
int width = 800;
int height = 600;
bool fullscreen = false;
};
int main() {
Window w{.height = 720, .width = 1280};
std::cout << w.width << 'x' << w.height << '\n';
return 0;
}
- A Window needs a constructor
- B C++20 designated initializers must follow the order in which the members are declared: {.width = 1280, .height = 720} Correct
- C bool members are not allowed
- D Designators need parentheses
Correct Answer: Option B
Skipping members is allowed (fullscreen keeps its default); reordering is not, unlike C.
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!