24 Nov 2019

  • November 24, 2019
  • Amitraj
We have presented you the sequence in which constructors and destructors get called in single and multiple inheritance.

*Constructor and destructor in single inheritance:

->Base class constructors are called first and the derived class constructors are called next in single inheritance.

-> Destructor is called in reverse sequence of constructor invocation i.e. The destructor of the derived class is called first and the destructor of the base is called next.


*Constructor and destructor in multiple inheritance:

-> Constructors from all base class are invoked first and the derived class constructor is called.

Order of constructor invocation depends on the order of how the base is inherited.

-> However, the destructor of derived class is called first and then destructor of the base class

Related Posts:

  • Overloading function Templates in C++ Overloading function Templates in C++ -> We may overload a function Template either by a non - template function template. -> if we call the name of an overloaded function template, the compiler will try to deduce it… Read More
  • Advantages / Benefits of Exception Handling Advantages of Exception Handling -> Following are the advantages of exception handling: 1. Exception handling separates the exception handling code from the main logic of program. 2. Exceptions can be handled outside … Read More
  • Exception specification in C++ Exception specification -> Older code may contain dynamic exception specifications. They are now deprecated in C++, but still supported. A dynamic exception specification follows the declaration of a function, appending … Read More
  • Templates in C++ Templates in C++ -> Templates is one of the features added to C++ Recently. it is a new concept which enable us to define Generic classes and functions and thus provides support for Generic programming. -> Generic pr… Read More
  • Static Class member in Class Template Static Class member in Class Template -> Each instantiation of class template has its own copy of member static variables. For example, in the following program there are two instances collection and collection. So … Read More

Translate

Popular Posts