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…

Base vs Derived Classes

One of the cool things about object oriented programming is that you can derive a class from an existing class. this allows you to have most of the class built from an existing class, and not need to rewrite the whole class, only the new parts. Additionally, if the original class, called the base class…

Copy Constructors

We’ve talked about Constructors in C++ already. One of the special methods, along with Destructors, that C++ offers. There is a third, special method which C++ offers. That is called a Copy Constructor. The Copy Constructor is a special type of constructor, which is intended for use when you duplicate an object. Some people will…

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…