LOGBOOK

HELP

Quiz Entry - updated: 2026.07.06

How do you declare a class in C++?

Write class Name { public: … private: … }; — and don't forget the trailing semicolon.

class ClassName {
public:
    // Public members (accessible from outside)
    ClassName(int x);          // constructor
    void method() const;       // method
private:
    // Private members (only accessible inside the class)
    int _member;
};   // <-- the semicolon is required

Example:

class Vehicle {
public:
    Vehicle(int nwheels);
    void show() const;
    int getNWheels() const;
private:
    int _nwheels;
};

Tip: The semicolon after the closing brace is mandatory (a class declaration is a statement). Forgetting it is one of the most common — and confusingly worded — beginner compiler errors.

Go deeper:

From Quiz: REVE1 / C++ Programming | Updated: Jul 06, 2026