我寫了使用大量的C++ 11元編程技術和CRTP一個小型圖書館,並與G ++ 4.7.2鏘和英特爾無法編譯這個CRTP代碼
現在編譯好了,我試着使用英特爾icpc 13.0.0.079進行編譯,並生成數百個錯誤。所以我試圖逐個隔離問題。
因此,首先,考慮下面的代碼,這在G ++ 4.7.2
#include <iostream>
template<template<typename> class Crtp, typename Type>
struct Base {};
template<typename Type>
struct Derived : public Base<Derived, Type>
{
Derived(): Base<Derived, Type>() {;}
};
int main()
{
Derived<int> x;
return 0;
}
兩個ICPC和鐺沒有問題編譯編譯失敗驗證碼:
test_crtp.cpp(26): error: type "Derived<Type>::Derived" is not a class template
Derived(): Base<Derived, Type>() {;}
^
test_crtp.cpp(26): error: "Base" is not a nonstatic data member or base class of class "Derived<int>"
Derived(): Base<Derived, Type>() {;}
^
detected during instantiation of "Derived<Type>::Derived() [with Type=int]" at line 31
compilation aborted for test_crtp.cpp (code 2)
因此,它是一個在英特爾和叮噹,或在g ++中的錯誤?如果它在英特爾和鏗鏘中,你認爲它將在未來的版本中得到解決嗎?
這是一個很好的問題,但通常CRTP不會打擾模板模板參數,但只是讓Derived類傳遞類型。 'template struct Base; template struct Derived:Base < Derived> {...};''是比較正常的。 –
...如果你想傳播'Type',可能你可以在'Derived'中有一個'typedef'來暴露它... – Nim
標識符'Derived'名稱,在它自己的類中,完整類型'Derived'。這被稱爲*注入*類名稱。我認爲這是GCC的一個錯誤。 –
Xeo