Re: derived class can not access base class protected member?

Tech-Archive recommends: Speed Up your PC by fixing your registry



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

.



Relevant Pages

  • Re: faster access private or public?
    ... > void f ... Whoops, Foo should have had: ... private, and make the original function a friend of Foo. ... Languages like Java have much more ...
    (microsoft.public.vc.language)
  • Re: Why does this compile with VC++?
    ... A foo() ... void bar() ... private. ...
    (microsoft.public.vc.language)
  • Re: Why does this compile with VC++?
    ... A foo() ... void bar() ... private. ...
    (microsoft.public.vc.language)
  • Re: Why does this compile with VC++?
    ... A foo() ... void bar() ... private. ...
    (microsoft.public.vc.language)
  • Re: Data Object Collection Inheritance
    ... > private System.Windows.Forms.ListBox listBox1;> private System.Windows.Forms.Button cmdID;> private System.Windows.Forms.Button cmdText; ... > private void InitializeComponent() ... > // TODO: Add BaseDataCollection.IsReadOnly getter implementation> return false; ... > public sealed class SubClassCollection: ...
    (microsoft.public.dotnet.languages.csharp)