我的問題可以通過下面的代碼段恢復:模板法和默認模板參數
template <typename T> struct C2;
template <typename T>
struct C1
{
template <typename Type,
template <typename Ti> class Container = C2>
void m() {}
};
template <typename T>
struct C2
{
template <typename Type = int,
template <typename Ti> class Container = C2> // <-- Here is the problem!
void m() {}
};
GNU編譯器,版本4.8.1失敗,出現以下消息:
test-temp.C:16:47: error: invalid use of type ‘C2<T>’ as a default value for a template template-parameter
template <typename Ti> class Container = C2>
它指的是方法C2 :: m的默認模板參數C2。
顯然(這是我的意見),編譯器看到C2<T>
作爲默認參數,而不是C2
(沒有<T>
)。因此,當它發現指令失敗時,因爲類型C2<T>
與Container
不匹配。
但是,鏗鏘++,只是爲了完全相同的代碼,編譯好!
我的問題:
- 哪個編譯器有真相?
- 是否有一些替代方案與gnu編譯器的當前版本表達相同的意義?
在此先感謝
萊昂德羅
g ++是錯誤的,鏗鏘是正確的,也是模板模板中的名稱是可選的 – aaronman