Answer the question
In order to leave comments, you need to log in
What is the difference between forward_list::iterator and _Fwd_list_iterator?
I'm probably dumb, but I can't figure out what's wrong.
The following code compiles without problems:
#include <forward_list>
template<typename T>
class Foo
{
std::_Fwd_list_const_iterator<T> cur;
//...
};
#include <forward_list>
template<typename T>
class Foo
{
std::forward_list<T>::const_iterator cur;
//...
};
$ g++ -c -std=c++11 1.cpp
1.cpp:5:5: error: need ‘typename’ before ‘std::forward_list<T>::const_iterator’ because ‘std::forward_list<T>’ is a dependent scope
std::forward_list<T>::const_iterator cur;
^
$ clang++ -c -std=c++11 1.cpp
1.cpp:5:5: error: missing 'typename' prior to dependent type name 'std::forward_list<T>::const_iterator'
std::forward_list<T>::const_iterator cur;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typename
1 error generated.
typedef _Fwd_list_const_iterator<_Tp> const_iterator;
Answer the question
In order to leave comments, you need to log in
The compiler prompts you: you need to add "typename".
Here you can read about it.
It works:
#include <forward_list>
template<typename T>
class Foo
{
typename std::forward_list<T>::const_iterator cur;
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question