C++

Advanced Function and Operator Overloading in C++

The following are the main point to keep in mind while dealing with Function and Operator Overloading in C++ – must differ in the type, number of parameters could not overload a function using a pointer and array as parameters. i.e void f(int *p); //error, *p is same as p[] void f(int p[]); The above…

Dynamic Allocation in C++
All Articles

Dynamic Allocation in C++

C++ provides allocation and deallocation functions ‘new’ and ‘delete’ similar to the malloc() and free() function in C. The main advantage of dynamic allocation is that it allows us to automatically allocate enough memory to hold an object of the specified type and you don’t need to use the ‘sizeof’ operator. Also, you don’t need…

C++ References
All Articles

C++ References

A reference is essentially an implicit pointer that acts as another name for an object. One important use for a reference is to allow you to create functions that automatically use call-by-reference parameter passing rather than C++’s default call-by-value method. When you create a reference parameter, that parameter automatically refers to (implicitly points to) the…

C++ pointer Arrays
All Articles

Arrays, Pointers and References in C++

C++ supports implementation of array of objects. Below is a simple implementation of array of objects – Note that we polymorphic constructors that acts upon the array, and one of them acts upon the array index and assign it to the class member ‘i’. Notice that the class object prints 0 when the un-initialized array…

C++ Static members
All Articles

Static Class Members in C++

Static data members are used when only one copy of the variable exists and all the objects of that class share that variable. It is mostly used to synchronize various objects accessing a shared variable. Below is a simple C++ program representing this functionality – Static member functions could only access members of a class….

C++ Inline Functions
All Articles

Inline Functions in C++

Inline functions are small functions defined with the inline keyword. The advantage of using inline functions are – They do not involve the usual stack operations as with ordinary function calls and returns, thus speeds up execution Usually used within classes which involves a lot of operations (small) on the private data It is professional…

All Articles

Friend Classes and Functions in C++

When a function is declared as friend, it is not a member of any class. But it could access the private and protected parts of the class. freind2.cpp below shows a member function of one class declared as a friend of another class – Below are the advantages of using friend functions – in operator…

C++ Keywords
All Articles

C++ Keywords

C++ provides a wide range of Keywords and much extensive than C programming offers. Below are the commonly used Keywords (reserved). alignas Used to precisely control the memory alignment of a user defined data/variable alignof returns in the alignment value in bytes of the specified type and bitwise AND operator and_eq equivalent to &= operator…

C++ Unions and Classes
All Articles

Unions and Classes in C++

C++ also supports unions as in C. They are functionally similar to that of a class but has the following limitations: All members are public by default Cannot be a base class to inherit other classes Cannot have virtual functions Cannot include static variable An object using a constructor and destructor cannot be a member…

C++ Constructor and Destructor
All Articles

Constructors & Destructors in C++

Constructor and Destructor functions are used in a class so as to automatically perform certain operations when an object of that class type is created and destroyed. For example, the constructor function named Stack() could be used to automatically initialize stktop = 0 when objects stack1 and stack2 are first executed. Similarly the destructor function…

All Articles

Inheritance in C++

Inheritance is the property of representing a base class and its derived classes as a hierarchy of classes with the most general functions of the class vested at the base or parent class and then specifying added qualities in each derived class. Below is an example of how we can represent a base class and…

All Articles

Function Overloading in C++

The principle of function overloading helps to implement polymorphism in C++ in which two or more functions share the same name (overloaded functions) and perform a general action but using different methods or approaches. The overloaded functions must differ in their function/method parameters/signatures and are defined and coded separately. They may or may not differ…

All Articles

Classes and Objects in C++

Classes are logical abstractions while Objects are instances of the classes that physical existence in the memory. Syntax for class declaration – We could use any number of access specifiers i.e, public, private, protected. But usually it is visually ordered if they are all grouped under only 3 headings. A class is instantiated as a…