C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Iterator problem with templates

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Patrick Leslie Polzer
Guest





PostPosted: Fri Jan 28, 2005 10:04 am    Post subject: Iterator problem with templates Reply with quote



Hi,

I have a problem with iterators at compile-time. The following program
will fail to compile:


#include <vector>

using std::vector;

template <typename T>
struct Test
{
};


template <typename T>
struct TestUser
{
vector<Test tests;

void test()
{
vector<Test::const_iterator iter; //line 18
}
};


int main()
{
return(0);
}


because:

tmpltest.cxx:18: error: expected `;' before "iter"


What's that? Is vector<Test::const_iterator an unknown type?

I hope someone can shed some light on this...
Back to top
Peter Kragh
Guest





PostPosted: Fri Jan 28, 2005 11:00 am    Post subject: Re: Iterator problem with templates Reply with quote



Patrick Leslie Polzer wrote:
<snip>
Quote:
template <typename T
struct TestUser
{
vector tests;

void test()
{
vector<Test::const_iterator iter; //line 18
}
};
snip

What's that? Is vector<Test::const_iterator an unknown type?

No. It's not an unknown type. However, it's a so-called dependant name.
Use typename. E.g.

void test()
{
typename vector<Test::const_iterator iter; //line 18
}

That shoule do the trick :-)

HTH

/Peter

Back to top
Patrick Leslie Polzer
Guest





PostPosted: Fri Jan 28, 2005 11:27 am    Post subject: Re: Iterator problem with templates Reply with quote



Peter Kragh wrote:
Quote:
No. It's not an unknown type. However, it's a so-called dependant name.
Use typename. E.g.

void test()
{
typename vector<Test::const_iterator iter; //line 18
}

That shoule do the trick Smile
Gah, that hit me a few days ago in another context.

The error message could really be more helpful :(

Many thanks!

Leslie

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.