Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBluefirehawk

Posted 13 August 2012 - 03:18 AM

I'm sorry Servant of the Lord, I have to disagree strongly.

A "break;" statement in a for loop doesn't make sense. By doing this:
for(vector<Container*>::iterator it = containers.begin(); it != containers.end(); it++)
{
		   if(!(*it)->getFull())
		  {
						 (*it)->addItem(itemAdd);
						 break;
		  }
}
You modified a for loop to a while loop. Hence what you really need here is a while loop.
Both works fine, it makes a difference when a Theoretical IT guy needs to verifiy the program.
A for loop is simple, it knows at runtime the exact amount of times the body is executed. A while loop is a bit more complicated. And by camouflaging a for loop in a while loop, you make the poor guy cry.


To the problem: it seems to me your problem lies in your OO class concept, or maybe a missing virtual keyword in a method. If you want to read up on the C++ virual keyword, www.learncpp.com had a good tutorial on it IMO.
I'm sorry, I cannot debug the code from where I currently am.

#1Bluefirehawk

Posted 13 August 2012 - 03:17 AM

I'm sorry Servant of the Lord, I have to disagree strongly.

A "break;" statement in a for loop doesn't make sense. By doing this:
for(vector<Container*>::iterator it = containers.begin(); it != containers.end(); it++)
{
		   if(!(*it)->getFull())
		  {
						 (*it)->addItem(itemAdd);
						 break;
		  }
}
You modified a for loop to a while loop. Hence what you really need here is a while loop.
Both works fine, the only difference is the semantic. It makes a difference when a Theretical IT guy needs to verifiy the program.
A for loop is simple, it knows at runtime the exact amount of times the body is executed. A while loop is a bit more complicated. And by camouflaging a for loop in a while loop, you make the poor guy cry.


To the problem: it seems to me your problem lies in your OO class concept, or maybe a missing virtual keyword in a method. If you want to read up on the C++ virual keyword, www.learncpp.com had a good tutorial on it IMO.
I'm sorry, I cannot debug the code from where I currently am.

PARTNERS