C++ Classes

A C++ class is a mechanism for creating user-defined data types. It is similar to the C-language structure, data type. In C, a structure is composed of a set of data members. In C++, a class type is like a C structure, except that a class is composed of a set of data members and an optional set of operations that can be performed on the class.

In C++, a class type can be declared with the keywords union, struct, or class. A union object can hold any one of a set of named members. Structure and class objects hold a complete set of members . Each class type represents a unique set of class members including data members, member functions, and other type names. The default access for members depends on the class key:

Once you create a class type, you can declare one or more objects of that class type.

For example:

class X
{ /* define class members here */ };
void main()
{
      X xobject1;       // create an object of class type X
      X xobject2;       // create another object of class type X
}

Classes are also used in C++ to support polymorphic functions through overloaded functions (static compile time binding) and virtual functions(dynamic binding). C++ allows you to redefine standard operators and functions through the concept of overloading. Operator overloading facilitates data abstraction by allowing you to use classes as easily as built-in types.



Dynamic Binding
Unions
Scope of Class Names


Class Members
Data Members
Virtual Functions
Declaring Class Objects
Overloaded Functions
Member Functions