2016-11-27 9 views
4

を動作しません:decltype(some_vector):: size_typeは、以下のクラスはコンパイルされませんテンプレートパラメータとして

template<class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key>> 
class MyContainer 
{ 
public: 
    std::vector<Key, Allocator> data; 
    std::vector<std::pair<std::size_t, decltype(data)::size_type>> order; 
}; 

は、私は、次のコンパイラエラーを取得:

error: type/value mismatch at argument 2 in template parameter list for ‘template struct std::pair’


はなぜことを行います次のコードは正常に動作しますが、コンパイルに失敗しますか?

あなたが依存 size_typeが実際に(例えばではなく、オブジェクト、)タイプで、コンパイラに指示する必要があり
template<class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key>> 
class MyContainer 
{ 
public: 
    std::vector<Key, Allocator> data; 
    std::vector<std::pair<std::size_t, std::size_t>> order; 
}; 

答えて

9

template<class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key>> 
class MyContainer 
{ 
public: 
    std::vector<Key, Allocator> data; 
    std::vector<std::pair<std::size_t, typename decltype(data)::size_type>> order; 
             ^^^^^^^^ 
}; 

std::size_tはそうそこに、テンプレートパラメータに依存しませんこの点で曖昧さはありません。

+2

まったく醜い! (しかしそれは働く...:/) –

+0

"そして、例えば、オブジェクトではない"、頭の爪に当たった。 – Surt

関連する問題