The Wayback Machine - https://web.archive.org/web/20210219161116/https://www.geeksforgeeks.org/c-virtual-functions-question-8/
Skip to content
Related Articles

Related Articles

C++ | Virtual Functions | Question 14
  • Difficulty Level : Medium
  • Last Updated : 12 Oct, 2013

Can a constructor be virtual?

Will the following program compile?

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <iostream>
using namespace std;
class Base {
public:
  virtual Base() {}   
};
int main() {
   return 0;
}

chevron_right


(A) Yes
(B) No


Answer: (B)

Explanation: There is nothing like Virtual Constructor. Making constructors virtual doesn’t make sense as constructor is responsible for creating an object and it can’t be delegated to any other object by virtual keyword means.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :