24 Nov 2019

  • November 24, 2019
  • Amitraj
Why A Constructor can not be Virtual

"A constructor can not be virtual". There are some valid reasons that justify this statement.

-> First, to create an object the constructor of the object class must be of the same type as the class. But, this is not possible with a virtually implemented constructor.

-> Second, at the time of calling the constructor, the virtual table would not have been created to resolve any virtual function calls.

-> Thus, a virtual constructor itself would not have anywhere to look up to. As a result, it is not possible to declare a constructor as virtual.

Related Posts:

  • Class Scope (C++ only) Class Scope in C++ -> A name declared within a member function hides a declaration of the same name whose scope extends to or past the end of the member function's class. -> When the scope of a declaration extends t… Read More
  • Inline Function in C++ Inline Function in C++ -> To eliminate the cost of calls to small functions, C++ proposes a new feature called, Inline function.            An inline function is a function that is expanded… Read More
  • Dynamic memory (Runtime) Allocation and Deallocation operator in C++ Dynamic memory (Runtime) Allocation and Deallocation operator -> Programmers can dynamically allocate storage space while the program is running, but programmers cannot create new variable names "on the fly", and for th… Read More
  • Static Data Member in C++ Static Data Member in C++ -> A data member of a class can be qualified as static .The properties of a static member variable are similar to that of C static variable. 1. It is initialized to zero when the first object … Read More
  • C++ Classes and Objects Class:- -> Language supports different data type like int, float, char, long, structure etc. Similar to that C++ supports class data type. -> A class is a user defined data type which has data members and member funct… Read More

Translate

Popular Posts