Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!mit-eddie!mit-amt!peter From: peter@mit-amt.MEDIA.MIT.EDU (Peter Schroeder) Newsgroups: comp.lang.c++ Subject: Re: Protected members Message-ID: <1111@mit-amt.MEDIA.MIT.EDU> Date: 29 Nov 89 14:47:36 GMT References: <1989Nov28.122925.20804@newcastle.ac.uk> Reply-To: peter@media-lab.media.mit.edu (Peter Schroeder) Organization: MIT Media Lab, Cambridge MA Lines: 44 In article lindsay@stobhill.newcastle.ac.uk (Lindsay F. Marshall) writes: class A { protected:: A(); ~A(); void* data; }; class B : public A { public: B(); ~B(); A* next; }; B::~B() { while (next != this) { delete next; } } >The compiler will not permit this access saying that the destructor is >protected. The same thing happens if one tries to access next->data. >Is this correct or is the compiler being too strict? This is correct. As a member of B, A* is just some class and can only be accessed as allowed by the original class definition. If we defined a class D which looks exactly like class A and then replaced the occurence of A* in B by D* it would be clear that we cannot expect to be able to access D's desctructor. I stumbled over this a few times, since 1.2.1 of cfront did not seem to enforce it, but I can now see that it makes sense to forbid this. Hope this helps. Peter peter@media-lab.media.mit.edu