Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndrew Perry
5,266 PointsWhy do I get this error?[SOLVED]
I get the following error when I run this code, can someone please tell me what is wrong?
Game.cs(13,37): error CS1729: The type TreehouseDefense.MapLoc
ation' does not contain a constructor that takes
3' arguments
MapLocation.cs(5,12): (Location of the symbol related to previo
us error)
MapLocation.cs(7,12): error CS0103: The name `map' does not exi
st in the current context
Here is my code for Game.cs using System;
namespace TreehouseDefense { class Game { public static void Main() { Map map = new Map(8,5);
try
{
MapLocation mapLocation = new MapLocation(20, 20, map);
}
catch(Exception)
{
Console.WriteLine("That map location is not on the map!");
}
}
}
}
and here is code for MapLocation.CS
namespace TreehouseDefense { class MapLocation : Point { public MapLocation(int x, int y) : base(x, y) { if (!map.OnMap(this)) { throw new System.Exception(); } } }
}
1 Answer
Steven Parker
231,271 PointsCongrats on figuring it out for yourself.
You could put [SOLVED] at the front of the title as an alternative to chosing a "best answer".
Andrew Perry
5,266 PointsAndrew Perry
5,266 Pointsits ok, I've worked it out. I hadn't passed a 3rd parameter to the MapLocation constructor