Cpp Tutorial: Object Slicing in C++

In this tutorial we shall see what is object slicing in C++ 1. Object Slicing occurs when a derived class object is assigned to the base class object. 2. Then, an instance of derived class object is copied into the base class object, omitting the additional attributes of derived class object. 3. It means the […]

Cpp Tutorial: Virtual Base Class in C++

In this chapter we shall see what is virtual base class and why we need virtual base class? We are aware of diamond problem in C++ #include<iostream> //for more C++ tutorial visit www.ProDeveloperTutorial.com using namespace std; class A { public: void display() { cout << "Hello form A \n"; } }; class B : public […]

Cpp Tutorial: Pure Virtual Functions and Abstract classes in C++

In previous chapter we saw what is a virtual function. In this chapter we shall see what is a pure virtual function and what is an abstract class. Pure virtual Functions: Pure virtual functions are the functions with “=0” at the end of their declarations. Below is the declaration of pure virtual function: virtual void […]

Cpp Tutorial: Dynamic or Runtime Polymorphism or Virtual Functions in C++

In this tutorial we shall learn about below topics 1. Need for virtual function 2. Virtual function example 3. Rules for a function to be virtual 1. Need for virtual function Consider below example. #include<iostream> using namespace std; class A{ public: void show(){ cout << " Hello from Class A"; } }; class B :public […]

Cpp Tutorial: Introduction to Polymorphism in C++

Poly means many, morphism means forms. Polymorphism in C++means one function behaving differently under different situations. 1. Compile time polymorphism a. Function overloading b. Operator overloading c. Function overriding 2. Run time polymorphism a. Virtual functions 3. Explicit and Implicit casting 1. Compile time polymorphism: The binding happens at compile time is called as Compile […]

Cpp Tutorial: Virtual Base Class and Virtual Inheritance in C++

In this chapter we shall learn about below topics: 1. What is the need of Virtual Base class? 2. How can we solve Diamond Problem with help of Virtual Base class. What is the need of Virtual Base Class? Consider the below program that is having a Diamond Problem. Here derived class “DerivedClass_3” is derived […]

Cpp Tutorial: C++ Types of inheritance:

Below are different types of inheritance: 1. Single Inheritance 2. Multiple Inheritance 3. Multilevel Inheritance 4. Hierarchical Inheritance 5. Hybrid Inheritance 6. Multipath Inheritance / Diamond Problem 7. Accessibility in Inheritance 1. Single Inheritance In this type of inheritance, there will be only 1 base class, and one derived class. It can be visualized as […]

Cpp Tutorial: C++ Inheritance

1. Introduction 2. Deriving by different access specifiers: 3. C++ Base class Pointer and Derived class pointer. 4. Virtual Base Class 5. Constructor and Destructor calls in Inheritance 6. Constructor and Destructor calls in Multiple Inheritance 7. Pointers and Inheritance 1. Introduction Inheritance is a way of creating new class with the help of existing […]

Cpp Tutorial: Copy Assignment operator in C++

In this chapter we shall learn about below topics: 1. Introduction 2. Syntax: 3. Need for user defined assignment operator. 4. User defined assignment operator example 1. Introduction: A user defined copy assignment operator is used to create a new object from an existing one by initialization. The compiler creates a default copy constructor and […]

Cpp Tutorial: Copy Constructor in Cpp

In this tutorial we shall understand about below topics. 1. Types of copy constructor 2. Overloaded copy constructor 3. Program for copy constructor 4. Why we need user defined copy constructor? 5. Why the argument to copy constructor should be pass by reference? 6. More complex example of user defined copy constructor: 7. what is […]