user1801067
user1801067

Reputation: 163

"Inconsistent accessibility: base class is less accessible than class"

Doing an assignment that a teacher has pretty much wrote us step by step how to do, I've had these 4 errors for a while but just ignored them.

Basically i have a parent class Menus with child classes PauseMenu, MainMenu, DifficultyMenu, and HelpMenu. The four errors i am getting say that the parent class is less accessible than the child class. Menu is abstract while the child menus are public, as instructed.

    #region Constructors
    protected Menu(MenuName menuName, Texture2D background, Rectangle drawRectangle)
    {
        this.menuName = menuName;
        this.background = background;
        this.drawRectangle = drawRectangle;
    }
    public Menu()
    {

    }
    #endregion

our professor specifically said to add a public constructor with no parameters specifically for this reason, but my IDE is still telling me that its wrong.

Any ideas on how to fix this?

Here is the constructor for the main menu

public MainMenu(Rectangle drawRectangle)
    : base(MenuName.MainMenu, SpriteDictionary.GetSprite("mainMenuBackground"), drawRectangle)
{}

here is the declaration of the class

namespace WackyPong.Menus
{
    public abstract class Menu
    {
        //all my code
    }

Upvotes: 0

Views: 7014

Answers (1)

David
David

Reputation: 10708

This error is usually related to class accessibility, as mentioned in comments. This can cause a problem since you expose a derived type via public but not the base type, and thus typecasting and inherited members enter a grey area of "do we expose these to other dlls?" - an area eliminated by this error refusing to build your project.

Seeing that the abstract base class is indeed public, have you made sure this applied to all of the types you've created? I note the use of a MenuName object in the constructor.

Note that this error will also show up if you have any public properties, fields, or methods which take or return types which are not publicly exposed - the compiler again enters that area of "the member is exposed, but the type included in its signature isn't."

Upvotes: 2

Related Questions