我正在尝试在模板中创建一种工厂类.我想做一些类似于纯虚函数的东西,但它需要是静态的,因为我正在使用该函数来创建类型.
我想要发生的是当我声明一个类时,模板调用静态函数.静态函数实际上是在templatised类中声明的.
我到目前为止:
class Base
{
};
template
class Type : public Base
{
public:
static void Create()
{
mBase = CreateBase();
}
private:
static Base* CreateBase();
static Base* mBase;
};
class MyType : public Type
{
private:
static Base* CreateBase()
{
return new MyType;
}
};
template
Base* Type::mBase = NULL;
void test()
{
MyType::Create();
}
我收到链接时间错误:
undefined reference to `Type::CreateBase()