I consider these so-called "virtual constructors" a bad design when used instead of constructors. These are nothing but virtual functions that are supposed to be called at the beginning of use of an instance of a class.
From the link you've posted:
class Browser
{
public:
//virtual default constructor
virtual Browser* construct() {return new Browser;}
};
Let's add a member field:
class Browser
{
int member;
public:
//virtual default constructor
virtual Browser* construct() {return new Browser;}
};
We need to initialize the member field, how do we do it?
class Browser
{
int member;
public:
//virtual default constructor
virtual Browser* construct()
{
Browser* b = new Browser;
b->member = 0;
return b;
}
};
Consider a situation when someone forgets to use template <class T> void func(T & obj) and does something like this:
Browser b;
printf("member=%d", b.member);
This way an uninitialized field is used. There is no way to prevent it.
Now, in this case
class Browser
{
int member;
public:
Browser() : member(0) { }
virtual Browser* construct() { /* some init stuff */ return new Browser;}
};
the default constructor is always used and member field always initialized.
However calling the construct() a "virtual constructor" I consider a naming abuse.
The pattern I showed above is quite common eg. in MFC. CWnd and similar classes use constructors to init instances and Create(...) functions to fully init and create controls. I would never call the Create(...) function a "virtual constructor", anyway.