Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.


Object factory(alias mod)(string classname);
Create instance of class specified by the module symbol and a string representing the name of the class. The class must either have no constructors or have a default constructor.
mod symbol representing the module that the class is in
string classname string representing the name of the class
null if failed



class C
    this() { x = 10; }
    int x;

void main()
    auto c = cast(C)factory!("C");
    assert(c !is null && c.x == 10);