Cpp Tutorial: Namespace in C++
In this chapter we shall learn about below topics: 1. Introduction 2. Declaring namespaces 3. Accessing namespace using “using” directive 4. The global namespace 5. The std namespace 6. Nested namespaces 7. Inline namespaces (C++ 11) 8. Namespace aliases 9. Anonymous or unnamed namespaces 10. Discontiguous Namespace in C++ 1. Introduction Namespace are used to […]
Cpp Tutorial: Working of Vtable and _vptr in C++
In this chapter we shall learn about vtable and _vptr in C++. vtable and _vptr is used to support runtime polymorphism or dynamic binding. Few Points about Vtable: vtable is also called as virtual table. vtable is used as lookup table during runtime. vtable gives the information about the function binding. All the class that […]
Cpp Tutorial: Order of Constructor and Destructor Call in inheritance in C++
In this chapter we shall see the order of Constructor and Destructor in inheritance 1. Order of Constructor and destructor call for simple inheritance 2. Order of Constructor and destructor call for multiple inheritance 1. Order of Constructor and destructor call for simple inheritance In this topic we shall see how the constructor and destructor […]
Cpp Tutorial: Virtual destructor and Pure virtual destructor in C++
Need for virtual destructor. When you delete a derived class object by using a base class pointer, the destructor call will be an undefined behavior. For example: In the below code, we are creating an object of derived class and assigning to base class pointer. Now when use “delete” operator, check the output: #include <iostream> […]
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 […]