【发布时间】:2012-04-29 18:12:36
【问题描述】:
关于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()
{
}
};
【问题讨论】: