MFC对象的动态创建 实例出错,求指导
#include <iostream.h>#include <String.h>
class CObject;
struct Cruntimeclass
{
char * classname;
CObject * (_stdcall * m_pnfCreateObject)();
CObject * _stdcall CreateObject();
};
class CObject
{
public:
virtual bool sayhello(){return true;}
};
class myclass:public CObject
{
public:
char * name;
public:
myclass(){name="myclass";}
static Cruntimeclass classMyclass;
static Cruntimeclass * getRuntimeClass();
public:
bool sayhello()
{
cout<<"hello me!"<<endl;
return true;
}
};
CObject * _stdcall CreateObject()
{
return new myclass;
}
Cruntimeclass myclass::classMyclass={
"myclass",
CreateObject};
Cruntimeclass * myclass::getRuntimeClass()
{
return &myclass::classMyclass;
}
void main ()
{
Cruntimeclass * p;
p=myclass::getRuntimeClass();
char inputClassName[10];
cin>>inputClassName;
if (!strcmp(inputClassName,p->classname))
{
p->CreateObject();
CObject * _stdcall pp=p->m_pnfCreateObject();
pp->sayhello();
}
else cout<<"no"<<endl;
}
错误提示如下:
--------------------Configuration: dynaCreat - Win32 Debug--------------------
Linking...
dynaCreat.obj : error LNK2001: unresolved external symbol "public: class CObject * __stdcall Cruntimeclass::CreateObject(void)" (?CreateObject@Cruntimeclass@@QAGPAVCObject@@XZ)
Debug/dynaCreat.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
dynaCreat.exe - 1 error(s), 0 warning(s)
表示看不太懂错误提示,是说"public: class CObject * __stdcall Cruntimeclass::CreateObject(void)" 无法识别吗?
还有一个不懂的地方,Cruntimeclass结构体生命中,若CObject * _stdcall CreateObject()去掉中间的 _stdcall则编译会提示,too many initializers这个又是怎么回事呢?
请高手指点!