结构初始化
问题描述:
我已经使用以下结构结构初始化
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>
问题在哪里?
什么是List类?你将如何构建一个常量列表- *的TSet
- ? –
geekazoid
2011-02-23 19:56:08
我看不到'List'是什么。另外,不要公开继承标准容器。有人会尝试多态地使用它并破坏你的代码。 – 2011-02-23 19:56:38