2017-03-03 116 views
3

例如如何定義模板的類型別名的一類

struct Option_1 
{ 
    template<class T> using Vector = std::vector<T>; 
}; 

我可以做

typename Option_1::Vector<int> v; 

但我更喜歡以下

Vector<Option_1, int> v; 

或同類者,而不單詞「typename」。我定義了別名

template<class Option, class T> using Vector= typename Option::Vector<T>; 

但由於無法識別模板聲明/定義而失敗。如何解決它?

+0

參見:* [在哪裏,爲什麼我必須把「模板」和「類型名」關鍵詞?(http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords)*。 – Pixelchemist

回答

1

你應該使用關鍵字template的依賴模板名稱Option::Vector,即

template<class Option, class T> using Vector = typename Option::template Vector<T>; 
//                ~~~~~~~~ 

LIVE