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…