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# Intermediate C# Polymorphism Virtual Methods

Error: Class, struct, or interface method must have a return type.

I keep getting this error for the SheildedInvader constructor. I can't tell what I'm missing. I named the class ShInvader. namespace TreehouseDefense { class ShInvader: Invader { private static System.Random _random = new System.Random();

  public ShInvader(Path path) : base(Path){}

  public override void DecreaseHealth(int factor)
   {         
     if(_random.NextDouble() < .5)
      {
       base.DecreaseHealth(factor);
      }
     else
     {
       System.Console.WriteLine("Shot blocked by sheild!!!");
     }
   }

} }

Steven Parker
Steven Parker
229,644 Points

To facilitate a complete analysis, make a snapshot of your workspace and post the link to it here.

Workspace Snapshot: https://w.trhou.se/wrxguetvhf

1 Answer

Steven Parker
Steven Parker
229,644 Points

The code shown here is not exactly the same as what you were working with in your workspace. As shown above, the class name is "ShInvader". But in the actual ShInvader.cs file in the workspace, the class name is just "Sh". This conflicts with the constructor name and causes the error.

Also, when the constructor calls the base, it should pass the variable "path" instead of the type "Path".

I got a new error: 'TreehouseDefense.path is a 'type' but a variable was expected. Its the constructor again.

https://w.trhou.se/wrxguetvhf

Steven Parker
Steven Parker
229,644 Points

A "snapshot" freezes the state of the project, so if you make changes, you'll need to make a fresh snapshot to share them.

But isn't this what I mentioned on the last line of my original answer? Have you made that change yet?