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++”
Tag: 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”
The ‘this’ Pointer Usage in C++
We discussed about the concept of this pointer in this article. The C++ compiler internally manages it. In general, we don’t need to worry about it. But there are scenarios where we need to use it explicitly. Resolving Ambiguity between Member and Input Variables A member function of a class deals with two types of … Continue reading “The ‘this’ Pointer Usage in C++”
The this Pointer in C++
In C++, the this pointer is generally used in the non-static member functions of a class. It refers to the address of the object the function is accessed through. Let’s understand the concept. C++ classes have mainly two types of components – properties (data) and functions. Every object, created from a class, will have a … Continue reading “The this Pointer in C++”