GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Feb-2009, 08:51
vivekc++ vivekc++ is offline
New Member
 
Join Date: Feb 2009
Posts: 1
vivekc++ is on a distinguished road
Lightbulb

What's the reason for these errors


CPP / C++ / C Code:
#include<iostream>
#include<list>

using namespace std;
                  
int main()
{
  list<int> dob;
    
   for(int i=0;i<5;i++)
   {
      dob.push_back(i);
   }   
  

   for(int i=0,list<int>::iterator itr=dob.begin();i<3;itr++,i++)
     cout<<*itr; 

 return 0;
}  

errors--
Code:
test.cpp: In function `int main ()': test.cpp:17: `iterator' specified as declarator-id test.cpp:17: extraneous `int' ignored test.cpp:17: `int list<int, allocator<int> >::iterator' is not a static member of `class list<int, allocator<int> >' test.cpp:17: parse error before `=' test.cpp:17: `itr' undeclared (first use this function) test.cpp:17: (Each undeclared identifier is reported only once for each function it appears in.)
Last edited by LuciWiz : 11-Feb-2009 at 10:56. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 11-Feb-2009, 13:05
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,311
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: What's the reason for these errors


Quote:
Originally Posted by vivekc++
CPP / C++ / C Code:

   for(int i=0,list<int>::iterator itr=dob.begin();i<3;itr++,i++)

This is trying todeclare itr to be an "int list<int>::iterator" data type.

If you are going to have multiple starting values in the for statement, and they are not the same type, don't try to declare them in the for statement. You could do something like
CPP / C++ / C Code:
   list<int>::iterator itr;
   int i;
   for(i = 0, itr = dob.begin(); i < 3; i++, itr++)
.
.
.

(In general, I would probably put in a test to make sure the iterator doesn't go beyond the end of the list:

CPP / C++ / C Code:
   for(i = 0,itr = dob.begin(); (i < how_many_you_want) && (itr != dob.end()); itr++)

Regards,

Dave
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 66 16-Jan-2010 10:53
Plz anyone help to fix the linking errors: dathatreya MS Visual C++ / MFC Forum 0 03-Apr-2008 00:19
Need urgent help. Nonsensical compile errors on test code (for game) seasons C++ Forum 1 29-Nov-2007 12:41
Compile Errors due to Default Parameters jdbrine C++ Forum 1 17-Jun-2006 14:45
Linker errors with multiple file progam nkhambal C Programming Language 2 24-Apr-2005 02:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:42.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.