After talking about constructors and destructors, next up in my series on object oriented programming is how to use setters. Setters are functions that are used to change the values of data members inside classes. They are very important, as they are the only route through which we can change the value of our data members after an object is instantiated.
Now that we”ve had a look at the types and uses of constructors, let us move on to the concept and use of destructors in C . Destructors are important in object oriented programming, as they are called whenever the life of an object ends. To understand destructors, first we must know that when dealing with classes, we often encounter a situation where pointers are used. A class with a pointer/pointers as data members are usualy allocated memory in a constructor. As a simple example, let us use a class called “point”, with a redundant data member called int * ptr.
You may recall i started a series about the basics of object oriented programming in C++. This is the second article of the series. Here, I give you an introduction to classes in C++, explaining about the basic syntax and structure, giving an example to illustrate just how to instantiate and use an object after declaring a class.