?
Solved

vector problem?

Posted on 2008-06-12
14
Medium Priority
?
275 Views
Last Modified: 2010-04-01
I have a segment of code which is failing. It's is something implement many other times, but somehow in this instance is not working. the code segment is:

vector<SystemNode*>::iterator node_itr = gvp_SystemNodes.begin();
while(node_itr != gvp_SystemNodes.end());
{
  ~~~~~~~
}

when it gets to the while statment, it is stuck in a loop. The code does not crash, it just forever loops inside the std vector code. I have not figured out whats its doing. Since that was really weird I also tried this:

vector<SystemNode*>::iterator node_itr = gvp_SystemNodes.begin();
while(node_itr != gvp_SystemNodes.begin());
{
  ~~~~~~~
}

And the code went right into the while loop. When in debug mode and watching the vector, it seems to evaluate correctly.  What could be going on here?

Thanks,

0
Comment
Question by:mattososky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
14 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 21774020
Are you actually incrementing the iterator ?

vector<SystemNode*>::iterator node_itr = gvp_SystemNodes.begin();
while(node_itr != gvp_SystemNodes.end());
{
  ~~~~~~~
  ++node_itr;
}
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21774029
Also, I assume that gvp_SystemNodes is defined as vector<SystemNode*> ?
0
 

Author Comment

by:mattososky
ID: 21774072
yes, <SystemNode*>...

Its not looping inside the while statement. It's looping inside 'gvp_SystemNodes.end()'. Never gets insode the while statement.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 53

Expert Comment

by:Infinity08
ID: 21774089
>> It's looping inside 'gvp_SystemNodes.end()'.

What do you mean by that ? What's inside the loop block ? Can you show the exact code you are using ? If that's not possible, can you create a small demonstration code that shows the problem ?

What compiler are you using ?
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21774130
>> It's looping inside 'gvp_SystemNodes.end()
Wow, that's a neat trick :)

There isn't really too much that can go wrong inside end() on VS2005 -- I agree with I8, we need code :)
0
 

Author Comment

by:mattososky
ID: 21774131
Ha! exactly my problem. I step through the code and it's inside the vector source code file, travles through about three functions until it returns the pointer. But then it executes the while statement again.

Have I hit a bug in the vector? Or something wrong with my compiler (VS2008)?

Again,, another very strange symptom,, listed in my intial post. If I set the while statment to !=~.begin(), it does enter the while statement when it clearly should not.

?
0
 
LVL 40

Accepted Solution

by:
evilrix earned 2000 total points
ID: 21774148
You have semi-colons are the end of your while statement!

while(pred); <---- LOOK
{
}
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21774150
>> Have I hit a bug in the vector?

For something as basic as this, it sounds quite unlikely.

Can you try creating a new project, and putting the code in there - just to make sure it's not related to project corruption of some kind.

Do you have the same problem for any code that loops through a vector ?

Can you show some complete sample code that has the problem ?


Are you sure that the compiler has been installed correctly ?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21774157
>> You have semi-colons are the end of your while statement!

Oh my ... Completely missed that lol
0
 

Author Comment

by:mattososky
ID: 21774160
There is another instance in the program where i declare a itr with a different name, but it works fine.
vector<SystemNode*>::iterator itr = gvp_SystemNodes.begin();
      while(itr!=gvp_SystemNodes.end())
      {


I would probably have to post alot of code for you to get the context....
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21774171
>> You have semi-colons are the end of your while statement!
Does your code behave as per my example below? If so I'd suggest that's your problem.
#include <vector>
 
typedef std::vector<int> intvec_t;
 
int main()
{
	intvec_t intvec(10);
	intvec_t::const_iterator i = intvec.begin();
 
	while(i != intvec.end());
	{
	}
}

Open in new window

0
 

Author Comment

by:mattososky
ID: 21774174
I'm a bad boy....
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21774182
>> I'm a bad boy....
Muhahahaha :)
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21774188
>> I'm a bad boy....

Yes you are ;) Confusing me like that lol. Glad evilrix was around to spot it, or I would have gone off on a wild goose chase heh.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question