Reputation: 2733
When i learn MFC
,, I want to imitate some mechanism, here, i just want to imitate MFC's the Mechanism of dynamic to create object Simple..Can you point out where is the fault, and how to finish it . Thank you...
class Object;
struct classRuntime
{
Object* pBasedClass;
Object* pNextClass;
char* className;
Object* CreateClass();
};
class Object
{
public:
static struct classRuntime ObjectClassRuntime;
Object() {
cout<<"Object constructor"<<endl;
}
static Object* CreateObject() {
return new Object;
}
};
classRuntime Object::ObjectClassRuntime = {NULL, NULL, "Object",
Object::CreateObject};
Upvotes: 0
Views: 103
Reputation: 465
class Object;
struct ClassRuntime {
Object* basedClass;
Object* nextClass;
char* className;
Object* (*instanceFactory)();
};
class Object
{
public:
static const ClassRuntime ObjectClassRuntime;
Object() {}
static Object* CreateInstance() { return new Object; }
};
const ClassRuntime Object::ObjectClassRuntime = {NULL, NULL, "Object", Object::CreateInstance};
class Toto : public Object
{
public:
static const ClassRuntime TotoClassRuntime;
Toto() {}
static Object* CreateInstance() { return new Toto; }
};
const ClassRuntime Toto::TotoClassRuntime = {NULL, NULL, "Toto", Toto::CreateInstance};
Upvotes: 1