By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Iterator problem with templates

P: n/a
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<T> > tests;

void test()
{
vector<Test<T> >::const_iterator iter; //line 18
}
};
int main()
{
return(0);
}
because:

tmpltest.cxx:18: error: expected `;' before "iter"
What's that? Is vector<Test<T> >::const_iterator an unknown type?

I hope someone can shed some light on this...
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Patrick Leslie Polzer wrote:
<snip>
template <typename T>
struct TestUser
{
vector<Test<T> > tests;

void test()
{
vector<Test<T> >::const_iterator iter; //line 18
}
}; <snip>
What's that? Is vector<Test<T> >::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<T> >::const_iterator iter; //line 18
}

That shoule do the trick :-)

HTH

/Peter
Jul 23 '05 #2

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

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

That shoule do the trick :-)

Gah, that hit me a few days ago in another context.
The error message could really be more helpful :(

Many thanks!

Leslie
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.