Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!PRINCETON.EDU!staelin From: staelin@PRINCETON.EDU (Carl Staelin) Newsgroups: gnu.g++.bug Subject: "virtual XXX operator XXX" functions Message-ID: <8905251621.AA10782@notecnirp.Princeton.EDU> Date: 25 May 89 16:21:37 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 76 There seems to be a bug in G++ version 1.35. I am running g++-1.35 on a vax 785 under the mach operating system (but this program was loaded without just the standard BSD4.3 libraries). I also ran it on a VAX 8650 running 4.3+NFS with the same result. The basic problem seems to be within "virtual XXX operator XXX" functions. The child has no means of accessing the parent's "operator XXX" function, and when it tries, the child simply calls itself. I have tried several means of specifying the parent function from within the child's function "operator XXX", including: Parent::operator XXX(), (XXX&)*(Parent*)this, and (XXX&)(Parent&)*this. All forms cause the child to call itself, not the parent's function. (some of them should call the child's routine, but parent::operator XXX() should call the parent's routine). Some sample source code follows: compiled as: g++ -o XXX XXX.cc // this may look like C code, but it is really -*- C++ -*- #include #include #include #include class Parent { public: Parent () { data = 5; } ~Parent() {} int data; virtual String operator String(); }; typedef Parent* Parent_p; class Child : public Parent { public: Child () { data = 10 ; } ~Child() {} virtual String operator String(); }; typedef Child* Child_p; main (int argc, char* argv[]) { Child child; String s = (String&)child; cerr< { data = %d }", (unsigned int)this, data); return result; } String Child::operator String() { cerr<<"Child::operator String(): entering\n"; String result = Parent::operator String(); return result; } /* Carl Staelin staelin@princeton.edu */