C++: Methods of a class

This entry is part 27 of 61 in the series C++

Earlier, we mentioned that a class consists of mainly the data members and methods.  As was shown, constructor or destructor are not something that is needed in order for a class to work.  You can choose not to declare them.

If they are not declared, the C++ program or the compiler will lazily create them for us.

In OOP, we sometimes talk about the characteristics of an object.  Those characteristics are the data members and the methods of a class.

Let’s consider using the train as an object.  We might have a data related to its speed and we might have a method that help us to calculate the no of days it takes to travel from one city to another.

Sometimes it is hard to work out the methods that are needed.  There were some who said this is designing the noun before coming out with the verb and it is something that we need to get use to.

When it comes to OOP, we talk about the re usability of a class.

At times, we might have designed a method that we use only once in our program.  This is actually ok as we can always improve them in our development process.



Series Navigation<< C++: Constructor with parameters
C++: Implementing a method >>