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# C# Objects Inheritance Inheritance in Code

Raiyan Rahman
PLUS
Raiyan Rahman
Courses Plus Student 8,091 Points

Unable to compile program.

Hello Everyone, I've been attempting to compile my Game program as described in the 2nd inheritance video but I'm encountering the following error when I try to compile the program:

"treehouse:~/workspace$ mcs -out:TreehouseDefense.exe *.cs
Game.cs(15,17): warning CS0219: The variable p' is assigned but its value is never used Point.cs(24,31): error CS0120: An object reference is required to access non-static memberTreeh ouseDefense.Point.X'"

Does anyone know what could be causing this?

I've taken a snapshot of my workspace so that you can reproduce the bug:

https://w.trhou.se/2d8y83mzk8

Thanks in advance.

1 Answer

Steven Parker
Steven Parker
231,275 Points

:point_right: You have a warning, and a typo:

This line in Game.cs was used in the video to demonstrate assignment of inherited types, but it was removed later. Even if left in, it does not cause an error, only a warning:

Game.cs
          Point p = x;

In Point.cs on this line:

Point.cs
      return DistanceTo(Point.X, point.Y);

You have written "Point.X" with a capital "P", but it should be "point.X".

Raiyan Rahman
Raiyan Rahman
Courses Plus Student 8,091 Points

Thanks for your help Steven, that cleared everything up.