home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15893 < prev    next >
Encoding:
Text File  |  1992-11-08  |  2.3 KB  |  84 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!rational.com!thor!rmartin
  3. From: rmartin@thor.Rational.COM (Bob Martin)
  4. Subject: Re: Quest: Multiple Virtual functions with same name
  5. Message-ID: <rmartin.721096943@thor>
  6. Sender: news@rational.com
  7. Organization: Rational
  8. References: <1992Oct30.182516.20463@hplabsz.hpl.hp.com> <BxAwAK.I1B@fulcrum.co.uk>
  9. Date: Sat, 7 Nov 1992 00:42:23 GMT
  10. Lines: 72
  11.  
  12. rct@fulcrum.co.uk (Richard Taylor) writes:
  13.  
  14. |In article <1992Oct30.182516.20463@hplabsz.hpl.hp.com> kalra@PROBLEM_WITH_INEWS_GATEWAY_FILE (Deven Kalra) writes:
  15. |>
  16. |>I have a question about having multiple virtual functions with same names.
  17. |>
  18. |>I have a base class as
  19. |>
  20. |>class BaseClass{
  21. |>
  22. |>
  23. |>    virtual render (Sphere &s);
  24. |>    virtual render (Rect   &r);
  25. |>}
  26. |>
  27. |>and a derived class
  28. |>
  29. |>class DerivedClass:public BaseClass{
  30. |>    virtual render (Sphere &s);
  31. |>}
  32. |>
  33. |>I get compiler warnings as:
  34. |>
  35. |>    render function hides base function
  36.  
  37. This is to be expected, members in derived classes "hide" members in
  38. base classes that have the same name.  See "ARM 13.1"
  39.  
  40. |>
  41. |>Is it documented behavior? Why does not 
  42. |>    render(Sphere &s) in DerivedClass
  43. |>
  44. |>replace 
  45. |>    render(Sphere &s) in BaseClass
  46.  
  47. It does.  But it also hides BaseClass::render(Rect&)
  48.  
  49. |>
  50. |>but 
  51. |>    render(Rect &r) be taken from the BaseClass.
  52.  
  53. Because it is hidden.  The ARM justifies this with a reasonably
  54. compelling argument.
  55.  
  56. |>
  57. |>
  58. |>Why should the above create a warning. Is there an alternative way
  59. |>to achieve the above functionality of replacing only some of the functions
  60. |>of a BaseClass that are named the same.
  61. |>
  62.  
  63. Yes,  You can add DerivedClass::render(Rect& r)
  64. {BaseClass::render(r);}
  65.  
  66.  
  67. |Isn't the problem that you have made *both* render (Sphere &s) functions
  68. |virtual? That means the base virtual function will *never* be used. Maybe
  69. |you meant:
  70.  
  71. |class DerivedClass:public BaseClass{
  72. |       /*virtual*/ render (Sphere &s);
  73.  
  74. No, virtualness has nothing to do with it.  The functions would have
  75. been hidden regardless of whether they were virtual or not.  In the
  76. example, it would appear that the functions ought to be virtual.
  77.  
  78.  
  79. --
  80. Robert Martin                        Training courses offered in:
  81. R. C. M. Consulting                       Object Oriented Analysis
  82. 2080 Cranbrook Rd.                        Object Oriented Design
  83. Green Oaks, Il 60048 (708) 918-1004       C++
  84.