Derived Classes

You can extend almost any class you want. So once you’ve defined a base class, you just need to know enough about it, and how you want to derive from it. Considering our GenericGeometric class from before, let’s look at deriving a Circle class from it. In our header file we will have: Notice two…

Destructors in C++

We’ve looked at Constructors in C++ to create an object, and building an object with new. However, what happens when we no longer need that object? That’s where a destructor is called. It is built into all objects, and if you don’t define one, a default one will be called for you. The destructor’s job…

Arrays of C++ Objects

We’ve talked about arrays and objects before, but now we’re going to look at an array of objects. Consider a situation where you had a class called Student. While you would often need to work with a singular student, you could very likely also need to have multiple students, for example, if you were talking…

C++ Constructors

Let’s look a little closer at constructors than we did in our initial Defining Classes for Objects example. Anytime you create an object, a constructor is called. If you overload your constructor, C++ will pick the right constructor to call, just like it does when you overload a function. Constructors must have the same name…

Creating an Object

Once you create your class, you need to create an object. The Class is just a blueprint for the program to follow. It doesn’t do anything until you create an object based off of that blueprint. Think of a house. If you have a house blueprint, all you have are some sheets of paper or…