Open In App

C++ | Virtual Functions | Question 14

Like Article
Like
Save
Share
Report

Can a constructor be virtual?

Will the following program compile?




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


(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


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads