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 trialElfar Oliver
3,924 PointsThe type `TreehouseDefense.MapLocation' does not contain a constructor that takes `3' arguments
I already had a look at a similar question but his code was complete and he had done more assignments so the answer for that didn't help with mine.
Here's the snapshot for the entire thing https://w.trhou.se/ambgl9ixrd
I tried changing the "public MapLocation" in line 5 in MapLocation.cs to "public mapLocation and then I got "MapLocation.cs(5,16): error CS1520: Class, struct, or interface method must have a return type"
2 Answers
Steven Parker
231,248 PointsIn Game.cs, on lines 15-22 there are 8 new MapLocation objects created, with each given 3 arguments.
But in MapLocation.cs, the constructor is defined on line 5 to take only 2 arguments. It looks like it was intended to have a third parameter named "map" (of type Map):
// public MapLocation(int x, int y) : base(x, y) // original
public MapLocation(int x, int y, Map map) : base(x, y) // modified
// ^^^^^^^
Mel Rumsey
Treehouse ModeratorHey Elfar Oliver!
I took a look at your workspace, so the error is pointing at this method public MapLocation(int x, int y) : base(x, y)
The error here is that it is not stating the return type. If the return type is an int
you'll need to make it public int MapLocation
if the return value is nothing, it should be public void MapLocation
etc.
Hope this helps!
Elfar Oliver
3,924 PointsThanks for replying, but it didn't work. I tried int, double, void, and string. I also don't remember in which video that code was made so I'll just take a break and study something else for a couple of days
Steven Parker
231,248 PointsMel, you should be aware that constructors never have a return type, not even "void".
Take a look at the section on Constructor syntax in the online documentation.
Elfar Oliver
3,924 PointsElfar Oliver
3,924 PointsThank you so much(yet again)! I got the same results as the teacher from compiling after I added Map map as a 3rd argument