Question 4
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
class Point {
public:
int x = 0, y = 0;
}
int main() {
Point p;
std::cout << p.x << '\n';
return 0;
}
- A Members cannot have default values
- B A class definition must end with a semicolon after the closing brace Correct
- C Point needs a constructor
- D x and y must be private
Correct Answer: Option B
Unlike function bodies, class definitions are declarations and need };. The compiler error often points at the next line.
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!