Structure initialization
I have used the following structure
template <typename Item>
struct TSet
{
typedef std::set <int, comparator <Item> > Type;
};
as a data member of the the structure
template <typename Item>
struct TObject
{
int code;
...
typename TSet <Item> ::Type indices;
TObject ( const List <Item> *list ) : code( 0 ), indices ( list ) {}
};
where
template <typename Item>
struct TList
{
typedef std::vector <Item> Type;
};
template <typename Item>
class List
{
private:
typename TList <Item>::Type items;
};
But I have changed the data model to
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 c开发者_如何学编程onvert parameter 1 const List <Item> to const TSet <Item>
};
and there are problems with the structure initialization.
Error: Can not convert parameter 1 const List <Item> to const TSet <Item>
Where is the problem?
Why would you expect a conversion from List
to TSet
if you did not write one? Also, the type of indices
needs a typename
on the front since it is a dependent type.
精彩评论