How Classes and Objects are implemented in C++
Object-oriented design in C++ with Kristoffer Hebert
Overview
A Class is a template for creating new objects. For example, a factory assembly line where a die-cast press presses metal into widgets. Classes are the die-cast and objects are the metal widgets.
What are Classes
A Class is a container, that has attributes of data, and class functions, also known as methods. Classes construct child objects and pass it’s own attributes to the child objects. Classes can also be extended, meaning attributes are copied and overwritten as a direct Class.
// Defining the DieCast Class
class DieCast {…}
What are Objects
Objects are instances of Classes. Objects inherit the attributes of the Class and are assigned to variables with the type of the Class.
// Constructing new object from DieCast Class
// Two ways to define new objectsDieCast widget(foo);
DieCast widget = new DieCast(foo);
Keys to remember
Classes are templates for objects and objects are instances of Classes. Classes can also be extended by other Classes. Extending means one Class copies another and overwrites attributes of another Classe. Objects can be constructed in two ways, see object code example.