//Forward declaration
class MyType;
class Factory{
template<class T>
static T* CreateObject(T& newOb){
return &newOb;
}
//Other non template functions
}
//In main (error causing line)
MyType tmptype;
MyType* newMyType = Factory::CreateObject<MyType>(tmptype);
此代码导致此错误: 未定义的参考`的MyType *厂::创建对象(的MyType &)”C++未定义的参考模板成员函数
我也得到这样的警告: 警告:自动导入已经在命令行中未指定--enable-auto-import的情况下被激活
此外,如果我使用int类型,它将无法正常工作,从而排除了未正确包含类型的可能性。
你在上课前缺少一个模板工厂 –
marinara
也在类定义上缺少结束分号。 –
请发布重现问题的代码,而不是随机的其他编译错误代码... – sth