Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15584
| From | Dan McLeran <danmcleran@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Private Virtual Methods |
| Date | 2012-04-26 06:58 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <8551872.423.1335448707115.JavaMail.geo-discussion-forums@ynfi5> (permalink) |
| References | <33500501.2151.1335304669864.JavaMail.geo-discussion-forums@ynmm10> <4f98fdf8$0$3095$7b1e8fa0@news.nbl.fi> |
> When specializing (non-pure) virtual functions in a derived class, it's > sometimes (or even often) the case that one wants to call the parent class > implementation as well. However, this becomes impossible if said > implementation is private. True. Sometimes that is the intent. > Suppose that in your example I would want to make a special type of 'Car' > by inheriting from it, and in its pressBrake() and pressGas() specializations > I would want to call the ones in the parent 'Car' class. Since they are > private, it's not possible. True as well. > > Is there a reason why the virtual functions cannot be in the protected > section? If one wanted to do what you've talked about above, that would be the way to go. If you wanted to explicitly prevent this behavior, then making them private is the answer. It all depends upon the behavior you're going for. In the case of this post, I was going for the simplest example which illustrates the idea. > (Also, putting member variables in a protected section is usually considered > dubious design. With respect to derived classes they are effectively public, > and as we know, public member variables are usually a bad idea, save for > some really exceptional cases.) It would definitely be better to make this member data private and provide getter/setter methods.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Private Virtual Methods Dan McLeran <danmcleran@gmail.com> - 2012-04-24 14:57 -0700
Re: Private Virtual Methods Paavo Helde <myfirstname@osa.pri.ee> - 2012-04-24 22:54 -0500
Re: Private Virtual Methods Dan McLeran <danmcleran@gmail.com> - 2012-04-25 06:58 -0700
Re: Private Virtual Methods Juha Nieminen <nospam@thanks.invalid> - 2012-04-26 07:49 +0000
Re: Private Virtual Methods Dan McLeran <danmcleran@gmail.com> - 2012-04-26 06:58 -0700
Re: Private Virtual Methods Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-04-27 00:40 -0400
Re: Private Virtual Methods Dan McLeran <danmcleran@gmail.com> - 2012-04-27 07:18 -0700
Re: Private Virtual Methods Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-04-28 10:10 -0400
Re: Private Virtual Methods nick_keighley_nospam@hotmail.com - 2012-04-29 05:01 -0700
Re: Private Virtual Methods Leigh Johnston <leigh@i42.co.uk> - 2012-04-28 16:35 +0100
csiph-web