NAVI NING

The very beginning mind itself is the most accomplished mind of true enlightenment.

Pointer to Class Members

Good approach to avoid code redundancy

Pointer to Class Members Pointer to Member Variables We all know that a pointer can used to represent the memory address of a variable. But what if the variable is inside a class? Let’ look at th...

Various Member Functions

In-depth understanding of the relationship between member functions

Various Member Functions We already know the properties of member functions. Member functions belong to the object of a class, and can only be called by that object. Now back to our Goods class, ...

Initializer List

Concise way in initializing data members

Initializer List Now let’s go back to the Goods class we wrote before. Suppose we want to add a production date to the goods, with a Data class: class Date { public: Date(int y, int m, int d) ...

Shallow Copy and Deep Copy

Issues in copying objects

Shallow Copy and Deep Copy Now let’s continue with our MyStack class. Suppose we create a MyStack object s1, and use it to create two other stacks s2 and s3, with either operator = or brackets. i...

Constructor and Destructor

Manage the lifecycle of an object

Constructor and Destructor Let’s look at the following code. Here we use object-oriented programming to implement a data structure stack. We use a dynamic array to store elements, and use member m...

Class and Object

Essences of object-oriented programming

Class and Object OOP (Object-Oriented Programming) is almost the most important programming paradigm nowadays. The following code is a class Goods which represents goods from a grocery. class Goo...

References in Detail

An alias for an existing variable

References in Detail References and Pointers A variable can be declared as reference with an & in the declaration. When a variable is declared as reference, it is an alias of an existing vari...

const and Pointers

Understand const in depth

const and Pointers const is a keyword widely used in C and C++. Variable modified byconst cannot be a Lvalue of operator =, which means it can not be modified after it is initialized. int main() ...

new and delete

Operators for memory management

new and delete There are two ways to create memory on heap. One original approach in C style is to use the library functions malloc and free: int main() { int *p = (int*)malloc(sizeof(int)); ...

Function Overloading

One of static polymorphism

Function Overloading In the following code, we have three compare functions that compare the value of two arguments. Notice that their function names are the same, but the arguments types are diff...