473,587 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<st d::vector<T,
std::allocator< _CharT >,std::allocato r<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 6218
On Feb 23, 3:11 pm, atomik.fun...@g mail.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<st d::vector<T,
std::allocator< _CharT >,std::allocato r<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
9147
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; memset(pTmp, 0, nDataSize + 1); //memcpy(pTmp, &m_pData, nDataSize);
20
17776
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; std::vector<double>::size_type size = src.size(); dest.reserve(size); for (std::vector<int>::size_type i = 0;
4
2398
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 >::iterator left, std::vector< myclass >::iterator right); x.hpp:153: error: `class std::vector<myclass, D>, std::alloca
9
8889
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; Any ideas why is tihs happening? The code is as follows: template <class T> struct StdVectorStorage { std::vector<T>* _storage;
4
5684
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 vector
10
1941
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
2453
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 searchable by an element (protocol, remote ip etc). The file is of known max width (65) containing 8 columns of known max size. The columns are seperated by...
7
5756
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 help, thank you. I am a freshman about the STL. The following is the code. #include <set> #include <iostream> #include <vector> int main() {
10
6056
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 remove the elements with odd values from your list * and the even values from your vector.
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.