Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!purdue!bu-cs!bloom-beacon!eru!luth!sunic!mcsun!ukc!newcastle.ac.uk!stobhill!lindsay From: lindsay@stobhill.newcastle.ac.uk (Lindsay F. Marshall) Newsgroups: comp.lang.c++ Subject: Protected members Message-ID: <1989Nov28.122925.20804@newcastle.ac.uk> Date: 28 Nov 89 12:29:25 GMT Sender: news@newcastle.ac.uk Organization: Computing Laboratory, University of Newcastle upon Tyne, UK, NE1 7RU Lines: 47 I have an application that worked under the 1.2 rules but wil not compile under 2.0. This seems to be to a considerable tightening of the rules for protected members. What I am not sure is whether or not it is correct!! The situation class A { protected:: A(); ~A(); void* data; }; class B : public A { public: B(); ~B(); A* next; }; So B is derived from and A and an instance of class B can access the field data without problems. However, if the class B uses an instance of class A inside one of its members, for example: 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? If it's correct is there any point in having a protected, non-virtual destructor - it might as well be private. This happens with both C++ 2.0 and g++ 1.36.1 . Lindsay -- MAIL : Lindsay.Marshall@newcastle.ac.uk (UUCP: s/\(.*\)/...!ukc!\1/) POST : Computing Laboratory, The University, Newcastle upon Tyne, UK NE1 7RU VOICE: +44-91-222-8267 FAX: +44-91-222-8232