Polymorphism is about a same piece of code behaves differently in different situations. In C++, polymorphism is achieved by function overloading, operator overloading, and virtual function overriding. Same interface, function or operation, can be bound to different object types, hence, different behaviors. Binding can happen compile time or runtime. Base on that polymorphism is categorized … Continue reading “Polymorphism in C++”
Tag: C++
Inheritance in C++
In Object Oriented Programming, inheritance is a mechanism of acquiring properties and behaviors in one class from another. In C++, one class can be derived from another class which is called base class. The derived class is often referred as a ‘child‘ class and the base one as ‘parent‘ class. It is like, the ‘child‘ … Continue reading “Inheritance in C++”
Friend Class in C++
The private and protected class members are not allowed to be accessed from outside the class. Only inherited or derived classes can access the protected members of its parent or base class. No other class or function can access them. But a friend class can access the private and protected members of a class where … Continue reading “Friend Class in C++”
Friend Function in C++
Private and protected class members are not allowed be accessed from outside the class. We can access the private members only from the same class, whereas, the protected members can be accessed from the same class and from its derived classes. But a friend function can access the private and protected members of the granting … Continue reading “Friend Function in C++”
Returning the ‘this’ Pointer from a Member Function
In C++, member functions get executed in the context of an object. And a special pointer, this, holds the address of that object. We can return the address (pointer), reference or a copy of that object using the this pointer from a member function of a class. Returning the Object Pointer Here the getPointer() function … Continue reading “Returning the ‘this’ Pointer from a Member Function”