473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 6203
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Vince | last post by:
Hi, I have replaced my BYTE* by a vector<BYTE> and before I used to do : void CCardRecord::GetRecData(int nOffset, int nDataSize, CString& csValue) { BYTE *pTmp = NULL; pTmp = new BYTE;...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
4
by: John | last post by:
I have a function declaration that gives an error while compiling. Can anyone help me figure this one out? inline void create(const std::vector< myclass >& plist, std::vector< myclass...
9
by: aaragon | last post by:
I am trying to create a vector of type T and everything goes fine until I try to iterate over it. For some reason, the compiler gives me an error when I declare std::vector<T>::iterator iter;...
4
by: arnuld | last post by:
i wrote a programme to create a vector of 5 elements (0 to 4), here is the code & output: #include <iostream> #include <vector> int main() { std::vector<intivec; // dynamically create a...
10
by: nerdrakesh | last post by:
Hi - Is there a method in STL vector to get the elements as an array instead of as a vector. Something like vector<intvt; vt.push_back(1); vt.push_back(2);
5
by: Etrex | last post by:
Hello, This is my first attempt at a c++ program, and it is a long post, please bear with me. I'm trying to read in a text file containing a firewall log, make the information...
7
by: Renzr | last post by:
I have a problem about the std::set<>iterator. After finding a term in the std::set<>, i want to know the distance from the current term to the begin(). But i have got a error. Please offer me...
10
by: arnuld | last post by:
WANTED: /* C++ Primer - 4/e * * Exercise: 9.26 * STATEMENT * Using the following definition of ia, copy ia into a vector and into a list. Use the single iterator form of erase to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.