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”

Method Chaining in C++

Method chaining is a mechanism of calling multiple functions (methods) in a single statement. It helps us reduce number of lines in the code and increase code elegancy. And in most cases it increases the code readability. Here in the class, c1, we have 3 member functions. First two functions set two variables – x … Continue reading “Method Chaining in C++”

Variable Name Ambiguity in Class Member Function

In C++, class member functions deal with primarily two types of variables – member variables and input variables. We don’t need to take special care in accessing them. C++ has a requirement that all member variables will have unique names. Similarly, all input variables will have unique names also. But an input variable of a … Continue reading “Variable Name Ambiguity in Class Member Function”

Backpointer – Concept and Application

We often work with data structures with connected nodes – like trees and graphs. In a tree, the parent nodes generally hold the pointers of their child nodes. But the child nodes can also hold the pointer back to their parent. Developers often refer this type of pointers as backpointers. In this diagram, the black … Continue reading “Backpointer – Concept and Application”

0
0
0
0
0
0