C++Tutorial for Beginners 32 - Getters and Setters

Getters and setters (known as accessors and mutators by computing professors who fell asleep in 1990 and have just woken up, or else are very fond of formal language) provide you with a direct way of getting and setting the values of your object's instance variables. Many point out, quite rightly, that this is almost as bad as exposing your instance variables and accessing them directly. But at least you can change your object's instance variables without altering the publicly-documented getters and setters. Getters and setters have, nevertheless, fallen out of favour in C++ and should be used only when you really need them, which is still quite often.

Click here to download source code for this tutorial.