Emplace using private constructor

develop32 develop32 at gmail.com
Fri Jun 7 05:23:30 PDT 2013


In a project I'm working on there are classes that are available 
publicly but I want to disable their construction outside of 
their modules.

class Display
{
    const string name;

    private this(string name)
    {
       this.name = name;
    }

    static Display[] all()
    {
       // Returns all available displays, the only place where 
Display objects
       // are to be constructed.
    }
}

This is easy when using "new". But I'm using std.conv.emplace 
which does not work with private constructors.

"Don't know how to initialize an object of type Display with 
arguments (string)"

Is there any solution to this problem? I know I can just make the 
constructor public but it just feels wrong, I want to keep public 
API as small as possible and it bugs me that language/library 
limits me here.


More information about the Digitalmars-d-learn mailing list