Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualTallkotten

Posted 12 August 2012 - 03:20 PM

FYI, I'll probably add more to this post in a little bit, so expect a few edits over the next hourish...


Item* itemMngr::createGold(int x, int y, int amount)
{
	Item* generateditem = NULL;
	generateditem = new Currency(x, y, amount);
	if(generateditem != NULL)
	{
		itemVector.push_back(generateditem);
	}
	return generateditem;
}

Don't do this. Not like that. new will not return NULL. Ever*. It will throw an exception if it fails. Specifically, it will throw a std::bad_alloc exception.
*At least it won't ever return NULL when called like that. You have to explicitly use nothrow if you want it to return NULL on an allocation failure instead of throw an exception.


Yeah, result of tiredness and a code-paste of the code above thanks thought, will fix it!

Also, thank you very much for putting for much time into this. Really kind of you!

#1Tallkotten

Posted 12 August 2012 - 03:18 PM

FYI, I'll probably add more to this post in a little bit, so expect a few edits over the next hourish...


Item* itemMngr::createGold(int x, int y, int amount)
{
	Item* generateditem = NULL;
	generateditem = new Currency(x, y, amount);
	if(generateditem != NULL)
	{
		itemVector.push_back(generateditem);
	}
	return generateditem;
}

Don't do this. Not like that. new will not return NULL. Ever*. It will throw an exception if it fails. Specifically, it will throw a std::bad_alloc exception.
*At least it won't ever return NULL when called like that. You have to explicitly use nothrow if you want it to return NULL on an allocation failure instead of throw an exception.


Yeah, result of tiredness and a code-paste of the code above thanks thought, will fix it!

PARTNERS