locked
"Base Class Field" is inaccessible due to its protection level

    Question

  • Tool: Visual Studio 2010 (Standard Edition)

    Hello Im getting this error ,i cant access base class fields through child class , im sure its due to access modifier on base class fields,I think protected access modifier is best suited for this situation but it doesn't work...I have even tried public (full open access) but getting same errors...

    Help me out

    Here is the code:

    namespace UrduEdit.Classes
    {
        //for storing DoubleState glyphs
         class UrduCharBase
        {
            protected char Alone;//will contain char state conditioned unicode char
            protected char End;//will contain char state conditioned unicode char
            public int State;//will contian enums for the state type
            UrduCharBase(char Alone,char End,int State )
            {
                this.Alone = Alone;
                this.End = End;
                this.State = State;
            }
            UrduCharBase()
            { }
        }

        //for storing QuadState glyphs
        class UrduCharChild : UrduCharBase
        {
            internal char Initial;
            internal char Middle;

            UrduCharChild(char Alone ,char Initial , char Middle , char End , int State)
            {
                this.Alone = Alone;
                this.Initial = Initial;
                this.Middle = Middle;
                this.End = End;
                this.State = State;
            }
            UrduCharChild()
            { }
        }
    }

     

    Error List:

    • 'UrduEdit.Classes.UrduCharChild.UrduCharChild(char, char, char, char, int)' is inaccessible due to its protection level
    • 'UrduEdit.Classes.UrduCharBase.Alone' is inaccessible due to its protection level
    • 'UrduEdit.Classes.UrduCharBase.End' is inaccessible due to its protection level
    • 'UrduEdit.Classes.UrduCharBase.State' is inaccessible due to its protection level

     

    Saturday, April 09, 2011 11:29 PM

Answers

  • Thanks for that...

    I have changed access modifier of parameter-less constructors(to internal) on both classes ...

    its now like this..

    //on setting protected i was not able to use constructor in another class with same namespace

            internal UrduCharBase()
            { }

            internal UrduCharChild()
            { }

    can you give me an insight why this was happening...?

    and what concepts should i revisit / brush up

    • Marked as answer by Abaf Sunday, April 10, 2011 7:41 AM
    Saturday, April 09, 2011 11:50 PM

All replies

  • You need to declare the constructors, or at least the parameterless constructor, in the base class as protected.

    --
    Mike
    • Proposed as answer by Evan Machusak Sunday, April 10, 2011 3:00 AM
    Saturday, April 09, 2011 11:36 PM
  • use should like below

     

        protected UrduCharBase(char Alone, char End, int State)
        {
          this.Alone = Alone;
          this.End = End;
          this.State = State;
        }
        
        protected UrduCharBase()
        {
        }
    

    Saturday, April 09, 2011 11:40 PM
  • Thanks for that...

    I have changed access modifier of parameter-less constructors(to internal) on both classes ...

    its now like this..

    //on setting protected i was not able to use constructor in another class with same namespace

            internal UrduCharBase()
            { }

            internal UrduCharChild()
            { }

    can you give me an insight why this was happening...?

    and what concepts should i revisit / brush up

    • Marked as answer by Abaf Sunday, April 10, 2011 7:41 AM
    Saturday, April 09, 2011 11:50 PM
  • Thanks for the input,,,

    i used internal because on setting protected i was not able to use constructor in another class with same namespace..

    Saturday, April 09, 2011 11:54 PM

  • All of your base classes constructors were private before.  Each class calls its base class' constructor, which yours was prevented from doing.  There was some discussion of this error and the misleading message it generates in the forums about a month ago.

    --
    Mike
    Sunday, April 10, 2011 12:09 AM
  • C# allows you to combine protected and internal:

    protected internal UrduCharBase() { }

    Specifically for cases like this.

    Evan

    Sunday, April 10, 2011 2:59 AM