saito@sdrvx2.sinet.slb.com (Naoki Saito (GEO-002) Ext. 5471) (12/01/89)
The function void f(Base& b) in the following program caused an error if I used the Sun C++ 2.0 translator as follows: ""prot.cc", line 18: error: Derived::f() cannot access Base::a: protected member Howerver, g++-1.34.2 on the Sun3 OS 4.0.1 did not produce any error. Which behavior is correct? (I think this is a 1.34.2 bug...) This g++ behavior is different from the g++-1.36.x? Thanks in advance, Naoki Saito (saito@sdr.slb.com) Schlumberger-Doll Research ========================prot.cc================================================ #include <stream.h> class Base { protected: int a; public: Base() { a = 100; } ~Base() {}; int get_a() { return a; } }; class Derived : public Base { public: Derived() : () { a = 10; } ~Derived() {}; void f(Base& b) { cout << a + b.a << "\n"; } void g(Base& b) { cout << a + b.get_a() << "\n"; } }; main() { Base x; Derived y; y.f(x); y.g(x); }