home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!gatech!concert!uvaarpa!murdoch!virginia.edu!gs4t
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Subject: Re: operator = with inheritance
- Message-ID: <1993Jan23.204010.5158@murdoch.acc.Virginia.EDU>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Organization: University of Virginia
- References: <1993Jan20.221834.26489@virginia.edu> <1993Jan14.184649.17113@ucc.su.OZ.AU> <727740820snx@trmphrst.demon.co.uk>
- Date: Sat, 23 Jan 1993 20:40:10 GMT
- Lines: 29
-
- nikki@trmphrst.demon.co.uk (Nikki Locke) writes:
- : gs4t@virginia.edu (Gnanasekaran Swaminathan) writes:
- : > g++ compiler gets this wrong. Probably try a different compiler
- : > if you are using g++.
- : I am afraid I think it is YOU who has got it wrong !
- :
- : I tested the program at the end of this post under Zortech c++ 3.0r4,
- : Borland C++ 3.0, and Microsoft C7, and they all gave the following output ...
- :
- : B::=(A&)
- : B::copy2(A*)
- : A::copy2(A*)
- : b1.b = 11 b2.b = 22 b1.a = 2 b2.a = 2
- :
- : If you follow this through,
- : a1=a2; calls the virtual operator B::operator=(const A&)
- : B::operator=(const A&) calls virtual function B::copy2(A*), NOT B::copy2(B*),
- : because polymorphism doesn't act on function arguments.
- :
- : Did you actually test this on some compiler ? If so, which one ?
- : _I_ think it has a bug !
-
- I fixed the gcc compiler myself to run the code as I thought
- it was a bug. I see what the problem is now. Thanks for catching
- the bug.
-
- Looks like you have to add a copy2 function to the base class
- for every derived class in this technique. There should be a
- better way.
-