469,898 Members | 1,471 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Error when compiling vector< T >::iterator

Hi, I'm re-writting my matrix class to practice my programming and the
computer doesn't let me compile the next code: ( this example come
from the constructor of the class)

//the matrix is made of vectors of vectors

template< typename T >
matrix< T >::matrix( unsigned rows, unsigned columns )
{
vector< vector< T ::iterator p;
....
}

if I change "vector< vector< T ::iterator p" to "vector< vector<
int ::iterator p"

then it compiles but it makes the use of templates useless because it
only works now for
matrix < int (obvious)

the error that i get in the latest g++ is:
error: dependent-name 'std::vector<std::vector<T,
std::allocator<_CharT >,std::allocator<std::vector<T,
std::allocator<_CharT ::iterator' is parsed as a non-type, but
instantiation yields a type.

Can someone explain me whats happening here and how to fix it.

thanks

Feb 23 '07 #1
1 5969
On Feb 23, 3:11 pm, atomik.fun...@gmail.com wrote:
Hi, I'm re-writting my matrix class to practice my programming and the
computer doesn't let me compile the next code: ( this example come
from the constructor of the class)

//the matrix is made of vectors of vectors

template< typename T >
matrix< T >::matrix( unsigned rows, unsigned columns )
{
vector< vector< T ::iterator p;
...

}

if I change "vector< vector< T ::iterator p" to "vector< vector<
int ::iterator p"

then it compiles but it makes the use of templates useless because it
only works now for
matrix < int (obvious)

the error that i get in the latest g++ is:
error: dependent-name 'std::vector<std::vector<T,
std::allocator<_CharT >,std::allocator<std::vector<T,
std::allocator<_CharT ::iterator' is parsed as a non-type, but
instantiation yields a type.

Can someone explain me whats happening here and how to fix it.
In the line "vector< vector< T ::iterator p;", the compiler does
not know that the part that becomes before p is the name of a type.
This is because you are allowed to specialise templates, making
iterator a non-type name.
The fix is to prefix the typename with the keyword typename:
typename vector< vector< T ::iterator p;

Your problem will not occur if you replace T with int because it now
knows the exact type of vector< vector< T and thus is aware that
the iterator of that class is indeed the name of a type.

/Peter

Feb 23 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Vince | last post: by
9 posts views Thread by aaragon | last post: by
4 posts views Thread by arnuld | last post: by
10 posts views Thread by nerdrakesh | last post: by
7 posts views Thread by Renzr | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.