home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!rational.com!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Subject: Re: Quest: Multiple Virtual functions with same name
- Message-ID: <rmartin.721096943@thor>
- Sender: news@rational.com
- Organization: Rational
- References: <1992Oct30.182516.20463@hplabsz.hpl.hp.com> <BxAwAK.I1B@fulcrum.co.uk>
- Date: Sat, 7 Nov 1992 00:42:23 GMT
- Lines: 72
-
- rct@fulcrum.co.uk (Richard Taylor) writes:
-
- |In article <1992Oct30.182516.20463@hplabsz.hpl.hp.com> kalra@PROBLEM_WITH_INEWS_GATEWAY_FILE (Deven Kalra) writes:
- |>
- |>I have a question about having multiple virtual functions with same names.
- |>
- |>I have a base class as
- |>
- |>class BaseClass{
- |>
- |>
- |> virtual render (Sphere &s);
- |> virtual render (Rect &r);
- |>}
- |>
- |>and a derived class
- |>
- |>class DerivedClass:public BaseClass{
- |> virtual render (Sphere &s);
- |>}
- |>
- |>I get compiler warnings as:
- |>
- |> render function hides base function
-
- This is to be expected, members in derived classes "hide" members in
- base classes that have the same name. See "ARM 13.1"
-
- |>
- |>Is it documented behavior? Why does not
- |> render(Sphere &s) in DerivedClass
- |>
- |>replace
- |> render(Sphere &s) in BaseClass
-
- It does. But it also hides BaseClass::render(Rect&)
-
- |>
- |>but
- |> render(Rect &r) be taken from the BaseClass.
-
- Because it is hidden. The ARM justifies this with a reasonably
- compelling argument.
-
- |>
- |>
- |>Why should the above create a warning. Is there an alternative way
- |>to achieve the above functionality of replacing only some of the functions
- |>of a BaseClass that are named the same.
- |>
-
- Yes, You can add DerivedClass::render(Rect& r)
- {BaseClass::render(r);}
-
-
- |Isn't the problem that you have made *both* render (Sphere &s) functions
- |virtual? That means the base virtual function will *never* be used. Maybe
- |you meant:
-
- |class DerivedClass:public BaseClass{
- | /*virtual*/ render (Sphere &s);
-
- No, virtualness has nothing to do with it. The functions would have
- been hidden regardless of whether they were virtual or not. In the
- example, it would appear that the functions ought to be virtual.
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-