Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!masotti From: masotti@usc.edu (Glauco Masotti) Newsgroups: comp.lang.c++ Subject: access to protected members Message-ID: Date: 17 Jul 89 18:08:44 GMT Sender: news@usc.edu Organization: University of Southern California Lines: 69 I had some problems using protected members. I was pretty confident, after reading the "evolution paper" from Bjarne, that my files would compile, but I received instead complains from the compiler. I am using g++, 1.35.0+, so I first thought of a bug in the compiler and I wrote to the FSF. I kept exchanging mail with Doug Lea. He told me I should be right, and that he also would like protected to work the way I used them, but that this doesn't conform to AT&T 2.0 specs. The interpretation of the evolution paper seems therefore to be cumbersome, but he also told me to have discussed the matter with Bjarne himself, to be sure of his interpretation. The following is the example: --------------------------------------- #include struct A { A(int i) {j=i;} void increment() {j++;} print() {cout<j"\n";} }; main() { int i=9; A a(i); a.increment(); a.print(); B b(2, 3, &a); b.print(); } ------------------------------------------------ Here a protected member of a class is accessed through a pointer in a member function of a derived class. To me this should be allowed, I find pretty counterintuitive the contrary. I would like to know what people think. If Andrew or Bjarne are listening I would appreciate very much their response. In any case if I cannot write something like the previous example, I think the cases where the protection mechanism will help instead of being a burden will shrink significantly. Therefore the problems protected was intended to solve (as reported in the evolution paper) will not be solved and we will be forced to resort again to public everything or make a lot of friends (which in C++ is not as good as in life :-)). -Glauco Masotti masotti@lipari.usc.edu P.S. This is my first posting, so... Hello to everybody! You may here from me again if I keep working on my current project.