home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19810 < prev    next >
Encoding:
Text File  |  1993-01-24  |  1.6 KB  |  41 lines

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