View Single Post
Old Nov 30th, 2006, 12:21 AM   #5
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
I have this now:
bool Valley::addEnergySource(int r, int c)
{
	//      TODO: implement addEnergySource
	//      If MAXSOURCES have already been added, return false.  Otherwise,
	//      dynamically allocate a new energy source at coordinates (r,c).
	//      Save the pointer to the newly allocated energy source and return true.
	//      (Hint:  The Valley class could contain a private array with MAXSOURCES
	//      elements.)
	if (m_nsources == MAXSOURCES)
		return false;
	else
	{
		EnergySource* es = new EnergySource(r,c);
		return true;
	}
}
Quote:
Note that the private array you have added for sources has the wrong size.
What do you mean here?

Anyways, I'm trying to extend this example to another mutator function:
	//      TODO: implement addRobot
	//      If MAXROBOTS have already been added, return false.  Otherwise,
	//      dynamically allocate a new robot whose name is name, at coordinates
	//      (r,c) facing in direction dir.  Save the pointer to the newly
	//      allocated robot and return true.  (Hint:  The Valley class could
	//      contain a private array with MAXROBOTS elements.)
bool Valley::addRobot(string name, int r, int c, Dir dir)
{
	if (m_nrobots == MAXROBOTS)
		return false;
	else
	{
		Robot* rob = new Robot(name, r, vp, c, dir);
		return true;
	}
}
I get one compilation error, that vp is not declared (true). If I take it out, it says I can't overload wtih 4 arguments. What's the wrongdoing here?
aznballerlee is offline   Reply With Quote