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 trial

C#

No over load for method DistanceTo

namespace TreehouseDefense { class MapLocation : Point { public MapLocation(int x, int y, Map map) : base(x, y) { if (!map.OnMap(this)) { throw new OutOfBoundsException(x + ", " + y + " is outside the boundries of the map."); } }

  public bool InRangeOf(MapLocation location, int range)
  {
   return DistanceTo(location) <= range; 
  }

}  

}

! followed everything in the video and this problem came up can someone please tell me whats wrong?

Steven Parker
Steven Parker
229,921 Points

To enable a complete and accurate analysis, make a snapshot of your workspace and post the link to it here. Also please provide a link the the course page you are working with.

Thank you very much, Steven. It means a lot that people are out there to help me learn :).

2 Answers

Timothy Schmidt
Timothy Schmidt
4,806 Points

In the vidoes, the only DistanceTo method in the Point class requires both an X and a Y to be passed to it.

return DistanceTo(Location.X, Location.Y) <= range;

The code you have was a mistake in the videos. He never shows it during the series, but if you download the project files, you'll find that they include a second function in the Point class that looks like this:

public int DistanceTo(Point point)
        {
            return DistanceTo(point.X, point.Y);
        }
Steven Parker
Steven Parker
229,921 Points

The error message seems to be correct.

In the current workspace program, there is no overload for DistanceTo that would take a single Location object argument. But I know the program evolves during the course, so perhaps you're at an intermediate stage right before one is to be made.

But for right now, you could substitute this line to call with the current requirements (Timothy was close, except for the name "location"):

       return DistanceTo(location.X, location.Y) <= range;