好奇地重复出现的模板-变化 [英] Curiously recurring template - variation
本文介绍了好奇地重复出现的模板-变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关于 CRP ,如果我想对它进行一些改动(使用模板template参数)时出现编译错误:
Regarding CRP if I want to implement a slight variation of it (using template template parameter) I get a compile error:
template <template <typename T> class Derived>
class Base
{
public:
void CallDerived()
{
Derived* pT = static_cast<Derived*> (this);
pT->Action(); // instantiation invocation error here
}
};
template<typename T>
class Derived: public Base<Derived>
{
public:
void Action()
{
}
};
我不确定是否会选择这种形式(对我而言不是编译形式)而不是使用这种形式(这种方式有效)
I am not exactly sure one would chose this form (that does not compile for me) instead of using this though (this works)
template <typename Derived>
class Base
{
public:
void CallDerived()
{
Derived* pT = static_cast<Derived*> (this);
pT->Action();
}
};
template<typename T>
class Derived: public Base<Derived<T>>
{
public:
void Action()
{
}
};
推荐答案
这也应该编译.我们只需要获取其他明确指定的模板参数
This should compile as well. We just need to get the other template parameter specified explicitly
template <typename T, template <typename T> class Derived>
class Base
{
public:
void CallDerived()
{
Derived<T>* pT = static_cast<Derived<T>*> (this);
pT->Action(); // instantiation invocation error here
}
};
template<typename T>
class Derived: public Base<T,Derived>
{
public:
void Action()
{
}
};
这篇关于好奇地重复出现的模板-变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文