### Classes and Structures

The C++ class is an extension of the C-language structure. Because the only difference between a structure and a class is that structure members have public access by default and a class members have private access by default, you can use the keywords class or struct to define equivalent classes.

For example, in the following code fragment, the class X is equivalent to the structure Y:

    // In this example, class X is equivalent to struct Y

    class X
    {
    int a; // private by default
    public:
          int f() { return a = 5; }; // public member function
    };
    struct Y
    {
    int f() { return a = 5; };       // public by default
    private:
          int a; // private data member
    };

If you define a structure and then declare an object of that structure using the keyword class, the members of the object are still public by default.

An aggregate class is a class that has no user-defined constructors, no private or protected members, no base classes, and no virtual functions.

Scope of Class Names

Example of Access for Classes and Structures

Base Classes
Constructors
Declaring Class Objects
Initializers
Private or Protected Members
Virtual Functions