How Classes and Objects are implemented in C++

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 objects
DieCast 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.

--

--

--

I am working toward a simpler, more meaningful world. kristofferhebert.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kristoffer Hebert

Kristoffer Hebert

I am working toward a simpler, more meaningful world. kristofferhebert.com

More from Medium

Basic Array knowledge in C++

In C++, write a method that remove a character from a C string using pointers

Operator Overloading in C++