Author Archive

The arrow operator (->) in C++

Written by Hamza. Posted in C++

arrow operator c++

Let us now look at another interesting feature that pops up whenever dealing with classes in C++: the arrow operator. The arrow operator is used to access member functions within a class through a pointer. It is a very useful feature and makes object oriented programming in C++ a lot easier.

Usage of this Pointer in C++

Written by Hamza. Posted in C++

this pointer c++

Thus far in this series on object oriented programming in C , we have learnt the basics of classes and objects and have touched upon the private data members and public member functions, including use of getters and setters in C . When dealing with a class, we create different objects and call a number of functions on them. Have you ever wondered: How does the compiler know on which object the function was called and to change the variables of which object inside that function? This is done using this pointer in C .

Use of constructors in C++

Written by Hamza. Posted in C++

constructors in C++

A constructor in a class is a special function called at instantiation of an object, or declaration of an object. What it does is simple: it does everything that you require to be done automatically every time an object of your class is created. This helps us to avoid system crashes and makes sure that the object we create does not always create variable or data that is unacceptable for our program. This will become clearer to you as you read on. 

Maintaining Classes in Separate Files in C++

Written by Hamza. Posted in C++

header and definition files

I previously mentioned in Basics of Object Oriented Programming that the main body of any class that we write in our program is usually written in a separate file called .cpp file and its declarations in another header file .h file. This is done in order to avoid clustering of the class definition with the execution body of the program. It makes it pretty easy and efficient to put all the classes in separate files in a large program. This is then included later in a main file and its functions are used in the manner we like. Here is the detailed procedure for it.