🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #958

protected != public-to-derived

#958
From: Bill Duttweiler
Date: Tue, 19 Mar 1991 16:53
42 lines
1619 bytes
I posted this to comp.lang.c++ a week ago, and haven't gotten any
feedback. Since I neglected to post to comp.std.c++, I thought I'd try
THAT before giving up on it...

Is it illegal to call a protected member function on an instance other
than 'this'? Consider the following simple example:

class A
{
public:
    A();
protected:
    void SetState();
};

class B : public A
{
public:
    B(A* a) { MyA = a; }
    void Foo() { MyA->SetState(); }
protected:
    A *MyA;
};

When run through g++ (1.37.1), I get the following error message:

test.cc: In method void B::Foo ():
test.cc:13: method `void A::SetState ()' is protected

When run through Sun C++ (based on cfront 2.0), I get

"test.cc", line 13: error:  B::Foo() cannot access A::SetState(): protected  member

So, these compilers agree. But I don't: B is publicly derived from A
and should have access to protected member functions from within its
own member functions. I can call SetState() on 'this', why not on
MyA???
-- 
William K. Duttweiler                   Schlumberger Austin Systems Center
(512) 331-3000                          PO Box 200015
wkd@asc.slb.com                         Austin, TX  78720-0015
Technical Details
Message-ID: <1991Mar19.165333.23908@asc.slb.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!ut-emx!slcs.slb.com!asc.slb.com!wkd

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!ut-emx!slcs.slb.com!asc.slb.com!wkd
From: wkd@asc.slb.com (Bill Duttweiler)
Newsgroups: comp.std.c++
Subject: protected != public-to-derived
Message-ID: <1991Mar19.165333.23908@asc.slb.com>
Date: 19 Mar 91 16:53:33 GMT
Sender: news@asc.slb.com
Organization: Schlumberger Austin Systems Center
Lines: 42
Nntp-Posting-Host: ash