davidm@uunet.UU.NET (David S. Masterson) (01/18/90)
The following test program illustrates what I think is a problem with G++. I am using G++ 1.36.1 on SunOS 3.5. The problem concerns improper use of the private data of a parent class by a child class member method. The program compiles fine and runs fine with the expected result (depending on your line of thought): N=3 X=1 ---------------- Code follows ---------------- #include <stream.h> class A { int x; public: A() { x = 1; } ~A() {} print() { cout << x << "\n"; } }; class B { static A* aptr; public: B(A* a) { aptr = a; } ~B() {} }; class C:B { int n; public: C(A* a, int z):(a) { n = z; } ~C() {} void testfunc(); }; void C::testfunc() { cout << "N=" << n << "\n"; cout << "X="; aptr->print(); } int main() { A testa; C testc(&testa, 3); testc.testfunc(); } ---------------- -- =================================================================== David Masterson Consilium, Inc. uunet!cimshop!davidm Mt. View, CA 94043 =================================================================== "If someone thinks they know what I said, then I didn't say it!"