關於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