C# C# Objects Inheritance Throwing Exceptions

Why 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 takes3' 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(); } } }

}

its ok, I've worked it out. I hadn't passed a 3rd parameter to the MapLocation constructor

1 Answer

Steven Parker
Steven Parker
149,228 Points

Congrats on figuring it out for yourself. :+1:

You could put [SOLVED] at the front of the title as an alternative to chosing a "best answer".