Data Field Encapsulation

Previously we looked at a class Circle, which had a property radius that was publicly available. That means that any other class, or your main program could change that value. This is a problem for two reasons: First, that data could be tampered with. Another function, class, etc could directly access the variable and change…

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…