Re: derived class can not access base class protected member?
- From: George <George@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 26 Oct 2007 02:23:02 -0700
Hi Peter,
I am not invoking foo in derived class, the error occurs when I invoke
destructor (protected, by using the statement delete b below). I am confused
why I can not access the protected method of base class in derived class?
void goo()
{
base* b = new derived;
delete b; // error in this line
}
have a good weekend,
George
"Peter Oliphant" wrote:
.private:
void foo()
Because foo( ) is defined as PRIVATE (not protected) in the base class
(typo?)... ;)
[==Peter==]
"George" <George@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D783AA73-AC91-45C2-B534-112BEFEC3BAA@xxxxxxxxxxxxxxxx
Hello everyone,
I met with a strange issue that derived class function can not access base
class's protected member. Do you know why?
Here is the error message and code.
[Code]
error C2248: 'base::~base' : cannot access protected member declared in
class 'base'
[/Code]
[Code]
class base
{
protected:
~base() {}
private:
void foo()
{
base* b = new base;
delete b;
}
};
class derived : public base
{
public:
~derived() {}
private:
void goo()
{
base* b = new derived;
delete b; // error in this line
}
};
[/Code]
thanks in advance,
George
- References:
- Re: derived class can not access base class protected member?
- From: Peter Oliphant
- Re: derived class can not access base class protected member?
- Prev by Date: Re: assert
- Next by Date: Re: Expiry date for microsoft support on vc++?
- Previous by thread: Re: derived class can not access base class protected member?
- Next by thread: Re: Vista vs XP
- Index(es):
Relevant Pages
|