Reputation: 752
I have a template class listmap
with a member called iterator
.
template <typename Key, typename Value, class Less = xless<Key>>
class listmap {
public:
class iterator;
//...
}
The definition for iterator is out of list map as follows,
template <typename Key, typename Value, class Less = xless<Key>>
class listmap<Key, Value, Less>::iterator {
//...
}
less
is a template class for comparison,
template <typename Type>
struct xless {
bool operator() (const Type& left, const Type& right) const {
return left < right;
}
};
I'm just running a simple test to see whether it works, but it gives me this error
cannot add a default template argument to the definition of a member of a class template
My understanding of template is very low. Why can't I use xless
in definition of iterator
here?
Upvotes: 0
Views: 70
Reputation: 9602
In your class declaration for listmap
you provide a default for the last template type (i.e., class Less = xless<Key>
).
In your definition of the iterator
you specify the default again, remove it.
template <typename Key, typename Value, class Less>
// ^^^^^^^^^^
class listmap<Key, Value, Less>::iterator
{
//...
}
Upvotes: 2