home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15876 < prev    next >
Encoding:
Internet Message Format  |  1992-11-07  |  1.8 KB

  1. Path: sparky!uunet!pipex!warwick!uknet!fulcrum!rct
  2. From: rct@fulcrum.co.uk (Richard Taylor)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Quest: Multiple Virtual functions with same name
  5. Message-ID: <BxAwAK.I1B@fulcrum.co.uk>
  6. Date: 6 Nov 92 15:27:55 GMT
  7. References: <1992Oct30.182516.20463@hplabsz.hpl.hp.com>
  8. Sender: Richard Taylor
  9. Organization: Fulcrum Communications
  10. Lines: 52
  11.  
  12. In article <1992Oct30.182516.20463@hplabsz.hpl.hp.com> kalra@PROBLEM_WITH_INEWS_GATEWAY_FILE (Deven Kalra) writes:
  13. >
  14. >I have a question about having multiple virtual functions with same names.
  15. >
  16. >I have a base class as
  17. >
  18. >class BaseClass{
  19. >
  20. >
  21. >    virtual render (Sphere &s);
  22. >    virtual render (Rect   &r);
  23. >}
  24. >
  25. >and a derived class
  26. >
  27. >class DerivedClass:public BaseClass{
  28. >    virtual render (Sphere &s);
  29. >}
  30. >
  31. >I get compiler warnings as:
  32. >
  33. >    render function hides base function
  34. >
  35. >Is it documented behavior? Why does not 
  36. >    render(Sphere &s) in DerivedClass
  37. >
  38. >replace 
  39. >    render(Sphere &s) in BaseClass
  40. >
  41. >but 
  42. >    render(Rect &r) be taken from the BaseClass.
  43. >
  44. >
  45. >Why should the above create a warning. Is there an alternative way
  46. >to achieve the above functionality of replacing only some of the functions
  47. >of a BaseClass that are named the same.
  48. >
  49.  
  50. Isn't the problem that you have made *both* render (Sphere &s) functions
  51. virtual? That means the base virtual function will *never* be used. Maybe
  52. you meant:
  53.  
  54. class DerivedClass:public BaseClass{
  55.        /*virtual*/ render (Sphere &s);
  56.  
  57.  
  58. Regards,
  59. ============================================================================
  60. Richard Taylor DoD #981 (rct@fulcrum.co.uk)              Heard on Radio 4:-
  61. "One of the first signs of the male menopause is buying a Harley Davidson."
  62. ============================================================================
  63. Fulcrum Communications Ltd., Fordrough Lane, Birmingham, B9 5LD, ENGLAND.
  64.