2014-04-22 38 views
0
template <type1 _Type1, type2 _Comparator=... > 

我想實現一個類。第一個參數可以是一個字符串,一個集合或一個列表。第二個參數是一個比較器。我想使用比較器<作爲type2的默認參數。默認參數和通用類

我沒有找到這個正確的語法,可能你幫幫我好嗎?

編輯:給出的答案是好的,但不是我的情況。 我意識到,我一直在尋找:

template <typename _Type, typename _Comparator=less<typename _Type::value_type> > 

,而不是

template< class Type1, class Comparator = std::less<Type1> > 

因爲我需要比較哪些是_Type的部分元素。

+1

怎麼樣'的std ::少' –

+0

沒錯,謝謝。 – anothertest

回答

1

認爲這可能是你追求的:

template< class Type1, class Comparator = std::less<Type1> > 

注意名稱以下劃線後跟大寫保留的實現。

std::less<functional>頭部聲明。