Container of iterators (newbie)

C

Carter

Hi,

I am trying to construct a container of iterators using STL and I seem
to be getting an error which I have been having difficulties figuring
out. The code is as follows:

std::list< std::list<K>::iterator > _scopes;

Which gives the following error:

type/value mismatch at argument 1 in template parameter list for
‘template<class _Tp, class _Alloc> class std::list’
environment.cpp:46: error: expected a type, got
‘std::list::iterator’
environment.cpp:46: error: template argument 2 is invalid

If anyone can shed light on this I would appreciate it.

Thanks in advance,
 
K

Kai-Uwe Bux

Carter said:
Hi,

I am trying to construct a container of iterators using STL and I seem
to be getting an error which I have been having difficulties figuring
out. The code is as follows:

std::list< std::list<K>::iterator > _scopes;

Which gives the following error:

type/value mismatch at argument 1 in template parameter list for
?template<class _Tp, class _Alloc> class std::list?
environment.cpp:46: error: expected a type, got
?std::list::iterator?
environment.cpp:46: error: template argument 2 is invalid

Presumably, the above line is part of a template and K is a typename
parameter to that template. Then, you should try:

std::list< typename std::list<K>::iterator > _scopes;


Best

Kai-Uwe Bux
 
C

Carter

Presumably, the above line is part of a template and K is a typename
parameter to that template. Then, you should try:

  std::list< typename std::list<K>::iterator > _scopes;

Best

Kai-Uwe Bux

Thanks that fixed the problem. I am however curious as to when in
general the addition of typename is required to disambiguate things
for the compiler. What exactly and when should you add the additional
typename keyword to a declaration?

Thanks,

Carter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top