| View previous topic :: View next topic |
| Author |
Message |
Patrick Leslie Polzer Guest
|
Posted: Fri Jan 28, 2005 10:04 am Post subject: Iterator problem with templates |
|
|
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
|
Posted: Fri Jan 28, 2005 11:00 am Post subject: Re: Iterator problem with templates |
|
|
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
|
Posted: Fri Jan 28, 2005 11:27 am Post subject: Re: Iterator problem with templates |
|
|
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
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 |
|
 |
|