Virtual function becomes pure virtual function by appending”=0″ to its declaration.
Let us try to understand pure virtual function with…
Category: C++98
Multiple Inheritance
In multiple inheritance, multiple classes are inherited i.e., when class needs properties of two or more classes and follows “Is-A” relationship as well.
Let us take an example to understand the concept of…
Overloaded new and delete operator for arrays
Overloading new and delete operator is very useful for our own memory management. Let us try to understand the overloading of new and delete operator for…
Inheritance
Inheritance is one of the core concepts of OOPS programming. Let us try to understand the basics of inheritance with…
Overload new and delete operator
new operator allocates the memory then calls the constructor. delete operator calls the destructor then delete the memory.
As these are operators, so it can be overloaded. But why we need to…
new and delete operator
new operator is used to allocate memory in runtime. This memory is allocated from heap segment of a process.
To understand how new operator…
Function Overloading
Function overloading is the type of static polymorphism. Function overloading means functions with same name but…
Composition
Every big thing is made up of small-small things. For example, a house is built from walls, ceiling, and doors. Now in terms of C++, we can say that every complex object is built from small or simple object. This process of creating a complex object from simple and small objects is called composition in C++. In other words, whenever there is “has-a” relationship, then composition comes in to picture. E.g., house has four walls, two doors and one ceiling. Let us try to understand the concept of composition with…
Explicit conversion constructor
Consider an example below to understand the concept of explicit constructor #include <iostream>using namespace std;class person {private: unsigned int m_age; char m_gender;public: person (unsigned int age = 40, char gender = ‘M’); bool operator==(const person& other) { cout << “Comparison”<< endl; if ((other.m_age == m_age) && (other.m_gender == m_gender)) { return true; } return false; }};person::person(unsigned int age, char gender){ cout << “C’tor” << endl; m_age = age; m_gender = gender;}int main() { person p(40, ‘M’); person p1 = 40; //Implicit conversion if ( p == 40) { //Implicit conversion…
Constructor & Destructor
Constructor :As name suggest, it construct an object. Constructor is used to initialize the data members of a class.Consider a class below: #include <iostream>#include <string> using namespace std;class employeeData { unsigned int m_salary; char* m_name;public: ~ employeeData() { //Destructor if (m_name) { delete []m_name; } } employeeData() { // default constructor cout << “employeeData default C’tor” << endl; m_salary = 0; m_name = NULL; } employeeData(unsigned int salary, char* name) { //Parameterized constructor cout << “employeeData parameterized C’tor” << endl; m_salary = salary; unsigned int len = strlen(name); m_name =…