Virtual

why we cannot give virtual to the class constructor?what is the reason? explain in brief.

In reply to Madineni:

Because it serves no purpose.

In reply to Madineni:

why we cannot give virtual to the class constructor?what is the reason? explain in brief.

A concept in OOP, we normally use a virtual-table in class object to manage and update virtual-function (early/late binding) for polymorphism. When you declare a function with virtual keyword, the program will update that function to virtual-table, then program can specify which function (base or derived) need to be executed when polymorphism happens.

The virtual-table is only existed after object is created/constructed (when call new()), that’s why we cannot declare virtual keyword before class constructor (new).