LearnFrenzy
Sign in Take a free test

OOPS Concepts · Find the Error · Question 4

Error: missing semicolon after a class definition Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

main.cpp
#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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links