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 ...
- 09-23-2009 #1Just 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; }
i get an error "Baseimage’ is an inaccessible base of ‘RGBclass’Code:Baseimage *pbase; RGBclass rgb; pbase = &rgb; cout<<" The channel is"<<pbase->ChannelType<<"\n";
why do i get that?
-swetha
- 09-23-2009 #2
Just a guess,try changing protected to public,
Swetha,Have you tried Debugging tools like GDB or Nemiver? which will help you to detect bugs more easily.class RGBclass
rotected Baseimage
- 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
-------------------
- 09-24-2009 #3Just 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
- 09-24-2009 #4
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
-------------------
- 09-25-2009 #5Linux Guru
- 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
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!
- 09-25-2009 #6Linux Guru
- 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
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!


Reply With Quote
