Function new() with virtual keyword

We implement constructor function new() in each class.
Its defined as function with no return type.
Why cant we specify it as virtual ?

Like

virtual function new();

In reply to bachan21:

When we declare a function as virtual , the function will be registered to a loop up table at the time object is created using default constructor .When we reference that virtual function it will be found implicitly from the look up table.
When we declare default constructor as virtual , the loop up table doesn’t exist yet for it ie even before object is constructed we are looking up the table. So the constructor function won’t be added to the LUT and hence it cant be declared as virtual.

In reply to bl4ckp3rl :

Hi Thanks for the reply.
Why do we avoid mentioning void return type to new() constructor

In reply to bachan21:

In reply to bl4ckp3rl :
Hi Thanks for the reply.
Why do we avoid mentioning void return type to new() constructor

Because it would be redundant.

This is patterned after other OOP languages like C++ and Java. The return type of the constructor can only be one type, the type of the class it is declared within. If you had to declare the return type, people might think you had a choice, which you don’t. Since new is a keyword, not a regular identifier, we can put this into the syntax.

In reply to dave_59:

Thanks Dave