Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualCornstalks

Posted 12 August 2012 - 04:06 PM

FYI, I'll probably add more to this post in a little bit, so expect a few edits over the next hourish... Whoa, didn't realize it was such a big code dump and it was a Code::Blocks project. Nevermind, I'm not gonna wade through it.

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. You should probablydefinitely be using smart pointers too.
*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.

#2Cornstalks

Posted 12 August 2012 - 03:16 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.

#1Cornstalks

Posted 12 August 2012 - 03:14 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.

PARTNERS