Object.factory
Arlen
arlen.albert at gmail.com
Thu Jun 7 11:55:49 PDT 2007
There was the 'factory' static method introduced in D some time ago. I haven't been succeeding in creating a single instance of any of my classes. The result of the function call is always 'null'.
What's going on?
An example code:
---------------------------------------------
import std.stdio;
alias char[] string;
int main(string[] args)
{
MyClass a = cast(MyClass) Object.factory("MyClass");
if(a !is null)
{
a.name = "Arlen";
a.family_name = "Keshabyan";
writefln(a.name ~ " " ~ a.family_name);
}
else
writefln("cannot create the MyClass class instance!");
}
class MyClass
{
private:
string m_name;
string m_family_name;
public:
this()
{
m_name = "";
m_family_name = "";
}
string name(){return m_name;}
void name(string value){m_name = value;}
string family_name(){return m_family_name;}
void family_name(string value){m_family_name = value;}
}
More information about the Digitalmars-d
mailing list