I have a DD class
template<typename T>
class DD
: public IEnumerable<T>
{
typedef IEnumerable<T> Super;
typedef std::set<T*> Container;
And a method
template<typename T>
bool DD<T>::Enumerator::Move()
{
if(!mIt.get())
mIt.reset(
new Container::iterator( <-----
mContainer.GetContainer().begin()
)
);
...
}
When I compile the class, I got error: expected type-specifier
.
What's wrong with the Container::iterator()
?
Without the
typename
, C++ will assumeX::Y
is a member (value/function) when X is in a template. You need thetypename
to force the compiler to interpretX::Y
as a type.Make that
For a thorough explanation, see this FAQ.
Try:
When you are in a C++ template, the compiler doesn't know whether Container::iterator is a type or something else. So you need to explicitly say that its a type.
On another note, creating an iterator with new is almost certainly wrong.