Class

A class is a abstract or user-defined data type, contrast to built-in fundamental types such as int or double . A class is represented as a three-compartment box: name, date members (or variables or attributes) and member functions (or methods, or operations). The data member and member functions are collectively called class members. The syntax of defining a class consists of two sections: class declaration and class implementation. Class declaration is further divided into two sections: private and public sections. Class implementation contains member function definitions.
// Declare constructor inside the class declaration
class ClassName {
   ClassName(parameter-list);   // prototype only
}
// Constructor implementation - identified via scope resolution operator
ClassName::ClassName(parameter-list)
{
   function-body;

}

Objects (or instances)

 An object (or instance) is a concrete realization of a class. For example, Point is a class, we can create instances (objects) p1, p2, p3, belonging to the class Point. You can invoke the constructor implicitly or explicitly as follows:

There are a few ways to use a class to create instances, as shown in the above test driver program:

➤ Construct instances (or objects) via constructors, either implicitly or explicitly.
➤ Declare object pointers, and construct the objects dynamically via new operator.
➤ Declare object references, and initialized to an existing object, or received as function reference argument.
➤ Array of objects, or Array of object pointers (dynamically allocated via new[] operator).

Comments

Popular posts from this blog

Covid-19 Analysis and Visualization using Plotly Express

Artificial Intelligence (Problem Solving)

Linear Regression