2011-02-23 201 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