LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-22-2005, 10:16 AM   #1
greg108
Member
 
Registered: Aug 2003
Location: CA USA
Distribution: FC2, FC4, Mandrake 10, Slackware 10, RedHat 9, Suse 9.1, College Linux, Debian Sarge, Gentoo
Posts: 170

Rep: Reputation: 30
c++ vector


I declare my vector like this:

vector<T> *places;
places = new vector<T>();

And then iterator like this:

vector<T>::iterator it;

And I get these warnings when I compile:

In file included from label.h:9,
from label.cpp:1:
vectorgrid.h: In member function `T* VectorGrid<T>::getObject(int, int)':
vectorgrid.h:42: warning: `std::vector<T, std::allocator<_CharT> >::iterator'
is implicitly a typename
vectorgrid.h:42: warning: implicit typename is deprecated, please see the
documentation for details


What should I change to get rid of these warnings?
My program compiles though and seems to work fine.
 
Old 06-22-2005, 10:25 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Are you actually using T? if so, what is it defined as?

If you put something like what's below in your code do you get warnings?

vector<int> *places;
places = new vector<int>();

vector<int>::iterator it;
 
Old 06-22-2005, 11:14 AM   #3
greg108
Member
 
Registered: Aug 2003
Location: CA USA
Distribution: FC2, FC4, Mandrake 10, Slackware 10, RedHat 9, Suse 9.1, College Linux, Debian Sarge, Gentoo
Posts: 170

Original Poster
Rep: Reputation: 30
T is defined as templete type, like this:

template<typename T>

I can't test it with int. The class would not make any sens.
I think there is something wrong with the way I declare an iterator for a vector that involves templete type.
The warning says 'it is implicitly a typename'. But how do I make it explicit? Maybe it needs some kind of qualifier.
 
Old 06-22-2005, 11:22 AM   #4
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348
Blog Entries: 1

Rep: Reputation: 37
for what I've read you need to make explicit declaration of the typename:
typename vector<T>::iterator it;

guess it works =)
 
Old 06-22-2005, 11:47 AM   #5
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Ah, I see, your using the vector inside your own Templated class then?
 
Old 06-22-2005, 12:01 PM   #6
greg108
Member
 
Registered: Aug 2003
Location: CA USA
Distribution: FC2, FC4, Mandrake 10, Slackware 10, RedHat 9, Suse 9.1, College Linux, Debian Sarge, Gentoo
Posts: 170

Original Poster
Rep: Reputation: 30
thanks guys.
 
Old 06-23-2005, 03:33 AM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
for what I've read you need to make explicit declaration of the typename:
typename vector<T>::iterator it;
Correct. This is only required within a template. The reason for this is that during the initial pass of the parser both templates (yours and std::vector) are incomplete types; there could be a partial specialization for vector <T> later on where ::iterator could be a function or a data member instead of a typedef in that specialization. The 'typename' tells the compiler that this will be a typename in the class vector<T> after all specializations are made (or aren't made). Even though "all" compilers are smart enough to figure this out, it's standard C++ and it makes your code a little bit more clear.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ vector bendeco13 Programming 4 11-04-2005 02:22 PM
vector like x ui oldstinkyfish Linux - Software 1 07-20-2005 11:36 AM
can i modify int 80 vector to a user-defined vector qqrilxk Linux - Security 1 03-03-2005 08:46 PM
Merge Two Vector values into new vector ArulPrabhuT Programming 2 09-23-2004 10:18 AM
Miseries at install from HDD&floppies, with vector ISO& how to boot with vector linux prctom VectorLinux 9 06-29-2004 05:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration