Find the answer to your Linux question:
Results 1 to 6 of 6
Hi , I am getting this error Code: class Baseimage { protected: enum ChannelType { RGB, Grayscale }; unsigned int plane; unsigned int interbitjump; unsigned int interbytejump; public: Baseimage(); Baseimage(unsigned ...
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    5

    Inaccessible Base -error

    Hi ,

    I am getting this error
    Code:
    class Baseimage
    {
    protected:
    enum ChannelType
    {
      RGB,
      Grayscale
    };
    
    unsigned int plane;
    unsigned int interbitjump;
    unsigned int interbytejump;
    public:
    Baseimage();
    Baseimage(unsigned int plane  ,unsigned int interbitjump ,unsigned int interbytejump):plane(plane),
                                                                                          interbitjump(interbitjump),
                                                                                          interbytejump(interbytejump){ }
    virtual void getrasterdata(ifstream&)=0;
    virtual void putrasterdata(ifstream&)=0;
    };
    
    class RGBclass:protected Baseimage
    {
      public:
    
        unsigned char* red;
        unsigned char* green;
        unsigned char* blue;
    }

    Code:
    Baseimage *pbase;
      RGBclass rgb;
      pbase = &rgb;
      cout<<" The channel is"<<pbase->ChannelType<<"\n";
    i get an error "Baseimage’ is an inaccessible base of ‘RGBclass’

    why do i get that?
    -swetha

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    Just a guess,try changing protected to public,
    class RGBclassrotected Baseimage
    Swetha,Have you tried Debugging tools like GDB or Nemiver? which will help you to detect bugs more easily.
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Just Joined!
    Join Date
    Sep 2009
    Posts
    5
    HI,
    Thankyou for the reply .I want to access the protected variable in the derived class.So ,i think i should use protected access.
    -swetha

  4. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    I haven't done anything related to C++ in last 4 years.Trying to recollect the stuff
    Can you post the complete code ..it might help some one from forum to help you .

    I'm not sure whether following stmt is correct ---

    protected can be accessed by it's public member function or friend function of the class
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by swethapradeep View Post
    Hi ,

    I am getting this error
    Code:
    class Baseimage
    {
    protected:
    enum ChannelType
    {
      RGB,
      Grayscale
    };
    
    unsigned int plane;
    unsigned int interbitjump;
    unsigned int interbytejump;
    public:
    Baseimage();
    Baseimage(unsigned int plane  ,unsigned int interbitjump ,unsigned int interbytejump):plane(plane),
                                                                                          interbitjump(interbitjump),
                                                                                          interbytejump(interbytejump){ }
    virtual void getrasterdata(ifstream&)=0;
    virtual void putrasterdata(ifstream&)=0;
    };
    
    class RGBclass:protected Baseimage
    {
      public:
    
        unsigned char* red;
        unsigned char* green;
        unsigned char* blue;
    }

    Code:
    Baseimage *pbase;
      RGBclass rgb;
      pbase = &rgb;
      cout<<" The channel is"<<pbase->ChannelType<<"\n";
    i get an error "Baseimage’ is an inaccessible base of ‘RGBclass’

    why do i get that?
    -swetha
    Because it is a protected base class. That means only friends can access member variables, even public ones, in that class directly. You might want to reconsider the reasons why you made Baseimage a protected base class. Generally, this is not necessary. If it is a public base class then a first-generation dervied class like RGBclass will be able to acces its variables.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by Rubberman View Post
    Because it is a protected base class. That means only friends can access member variables, even public ones, in that class directly. You might want to reconsider the reasons why you made Baseimage a protected base class. Generally, this is not necessary. If it is a public base class then a first-generation dervied class like RGBclass will be able to acces its variables.
    Sorry, this is not exactly correct. A first-generation derived class such as RGBclass can access a protected base class' non-private members, but an external function or other class cannot. Also, the variables you tried to access are protected in the Baseimage class, so only friends of that class, or first-generation derived classes, will be able to access them in any case.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...