2011-02-23 203 views
0

我已經使用以下結構結構初始化

template <typename Item> 
struct TSet 
{ 
    typedef std::set <int, comparator <Item> > Type; 
}; 

爲其中

template <typename Item> 
struct TList 
{ 
    typedef std::vector <Item> Type; 
}; 

template <typename Item> 
class List 
{ 
    private: 
      typename TList <Item>::Type items; 
}; 

但是我已經改變了數據模型

的結構

template <typename Item> 
struct TObject 
{ 
    int code; 
    ... 
    typename TSet <Item> ::Type indices; 

    TObject (const List <Item> *list) : code(0), indices (list) {} 
}; 

的數據成員

template <typename Item> 
class TSet : public std::set <int, comparator <Item> > 
{ 
}; 

template <typename Item> 
struct TObject 
{ 
    int code; 
    ... 
    typename TSet <Item> indices; 

    TObject (const List <Item> *list) : code (0), indices (list) {} //Error: Can not convert parameter 1 const List <Item> to const TSet <Item> 
}; 

並且存在結構初始化的問題。

Error: Can not convert parameter 1 const List <Item> to const TSet <Item> 

問題在哪裏?

+0

什麼是List類?你將如何構建一個常量列表 *的TSet ? – geekazoid 2011-02-23 19:56:08

+3

我看不到'List'是什麼。另外,不要公開繼承標準容器。有人會嘗試多態地使用它並破壞你的代碼。 – 2011-02-23 19:56:38

回答

0

如果你沒有寫一個,爲什麼你會期望從ListTSet的轉換?此外,indices的類型在前面需要typename,因爲它是依賴類型。

+0

你能舉個簡單的例子嗎? – Robo 2011-02-23 20:16:54

+0

@Robo:什麼樣的例子? – 2011-02-23 20:17:37

+0

我重寫了對typename TSet 索引的聲明。項目列表僅用於比較器比較器的初始化。我不確定是否需要轉換函數... – Robo 2011-02-23 20:29:57