【发布时间】:2022-01-08 20:09:41
【问题描述】:
我认为答案很简单,但我无法找到解决方案。
我有一个类用作 h 文件中的接口:
template <typename T>
class MyInterface
{
public:
MyInterface();
};
在 cpp 文件中是:
#include "MyInterface.h"
template<typename T>
MyInterface<T>::MyInterface()
{
}
我使用该接口的类是:
class Test : MyInterface<int>
{
};
编译时出现错误,未声明 MyInterace 的 ctor。
函数“public: __thiscall Test::Test(void)”中引用的未解析外部符号“public: __thiscall MyInterface::MyInterface(void)”(??0?$MyInterface@H@@QAE@XZ)
在 h 文件中声明了 ctor,它就可以编译了。
【问题讨论】:
-
有人可以回答吗?
标签: c++ templates constructor