Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Why C++ does not have a virtual constructor?
The virtual mechanism works only when we have a base class pointer to a derived class object.
In C++, constructor cannot be virtual, because when constructor of a class is executed there is no virtual table in the memory, means no virtual pointer defined yet. So, the constructor should always be non-virtual.
But virtual destructor is possible. Here is an example
Example
#includeusing namespace std; class b { public: b() { cout Output
Constructing base Constructing derived Destructing derived Destructing base
Advertisements
