mattososky
asked on
vector problem?
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*>::itera tor 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*>::itera tor 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,
vector<SystemNode*>::itera
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*>::itera
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,
Also, I assume that gvp_SystemNodes is defined as vector<SystemNode*> ?
ASKER
yes, <SystemNode*>...
Its not looping inside the while statement. It's looping inside 'gvp_SystemNodes.end()'. Never gets insode the while statement.
Its not looping inside the while statement. It's looping inside 'gvp_SystemNodes.end()'. Never gets insode the while statement.
>> 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 ?
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 ?
>> 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 :)
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 :)
ASKER
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.
?
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.
?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> 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 ?
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 ?
>> You have semi-colons are the end of your while statement!
Oh my ... Completely missed that lol
Oh my ... Completely missed that lol
ASKER
There is another instance in the program where i declare a itr with a different name, but it works fine.
vector<SystemNode*>::itera tor itr = gvp_SystemNodes.begin();
while(itr!=gvp_SystemNodes .end())
{
I would probably have to post alot of code for you to get the context....
vector<SystemNode*>::itera
while(itr!=gvp_SystemNodes
{
I would probably have to post alot of code for you to get the context....
>> 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.
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());
{
}
}
ASKER
I'm a bad boy....
>> I'm a bad boy....
Muhahahaha :)
Muhahahaha :)
>> 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.
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.
vector<SystemNode*>::itera
while(node_itr != gvp_SystemNodes.end());
{
~~~~~~~
++node_itr;
}