模板类中的模板方法,在类外定义

Template method in template class with definition outside class

本文关键字:定义 模板方法      更新时间:2023-10-16

我想有一个内部带有模板方法的模板类,并在类外部定义该方法。我试着四处寻找答案,但找不到。

例如:

template<typename A> class Type {
private:
A value;
public:
template<typename B> A Method(B value) {
// some code here, it's not important for the sake of this example
}
}

如何将方法Method的定义移动到类主体之外?提前谢谢。

语法将是

template<typename A>
template<typename B>
A Type<A>::Method(B value)
{
// some code here, it's not important for the sake of this example
}