关于CRP如果我要实现它(使用模板的模板参数)有轻微的变化,我得到一个编译错误:奇怪的循环模板 - 变化
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()
{
}
};
我不完全相信人会选择这种形式(无法编译对我来说),而不是使用这虽然(这个工程)
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()
{
}
};
非常有趣的一个必须在声明中明确指出typename T两次...不明白为什么 – Ghita
刚刚意识到派生必须传递它的T参数。 – Ghita