Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #80637
| Subject | Re: dynamic_cast |
|---|---|
| Newsgroups | comp.lang.c++ |
| References | <20210627225136.00005d66@reddwarf.jmc> <sbbr3u$a3j$1@dont-email.me> <sbl7mh$kb5$1@dont-email.me> <sbpm58$tfv$1@dont-email.me> |
| From | Richard Damon <Richard@Damon-Family.org> |
| Message-ID | <oMZDI.15364$SA.31@fx39.iad> (permalink) |
| Organization | Forte - www.forteinc.com |
| Date | 2021-07-03 09:39 -0400 |
On 7/3/21 8:45 AM, Bonita Montero wrote: >> I just did a line count on our codebase; we have about 1 dynamic >> cast for every 10k lines. Compare with static_cast - 1 in 300. > > Using dynamic_cast instead of a virtual function call is bad coding. Incorrect, often to add the virtual function call to get around the need for the dynamic_cast requires injecting into a class concepts that it should not be dealing with. As an example, say you have a collection of animals, and you want to extract all the dogs out of it. You could add to Animal and Dog an isDog function, (and then need to change Animal again for each new type of thing you might want get, lousy encapsulation) or you can use a dynamic_cast to check if this animal is a Dog.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
dynamic_cast Mr Flibble <flibble@reddwarf.jmc> - 2021-06-27 22:51 +0100
Re: dynamic_cast Öö Tiib <ootiib@hot.ee> - 2021-06-27 15:01 -0700
Re: dynamic_cast Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-06-27 22:30 +0000
Re: dynamic_cast "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-06-27 16:35 -0700
Re: dynamic_cast Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-28 08:44 +0200
Re: dynamic_cast Vir Campestris <vir.campestris@invalid.invalid> - 2021-07-01 21:14 +0100
Re: dynamic_cast Öö Tiib <ootiib@hot.ee> - 2021-07-01 14:16 -0700
Re: dynamic_cast red floyd <no.spam.here@its.invalid> - 2021-07-01 17:48 -0700
Re: dynamic_cast Bonita Montero <Bonita.Montero@gmail.com> - 2021-07-03 14:45 +0200
Re: dynamic_cast Richard Damon <Richard@Damon-Family.org> - 2021-07-03 09:39 -0400
Re: dynamic_cast Bonita Montero <Bonita.Montero@gmail.com> - 2021-07-03 15:53 +0200
Re: dynamic_cast Richard Damon <Richard@Damon-Family.org> - 2021-07-03 09:59 -0400
Re: dynamic_cast Bonita Montero <Bonita.Montero@gmail.com> - 2021-07-03 17:01 +0200
Re: dynamic_cast Richard Damon <Richard@Damon-Family.org> - 2021-07-03 11:42 -0400
Re: dynamic_cast Bonita Montero <Bonita.Montero@gmail.com> - 2021-07-03 18:04 +0200
Re: dynamic_cast Richard Damon <Richard@Damon-Family.org> - 2021-07-03 13:59 -0400
Re: dynamic_cast Mr Flibble <flibble@reddwarf.jmc> - 2021-07-03 20:06 +0100
Re: dynamic_cast Bonita Montero <Bonita.Montero@gmail.com> - 2021-07-04 07:06 +0200
Re: dynamic_cast Richard Damon <Richard@Damon-Family.org> - 2021-07-03 14:03 -0400
Re: dynamic_cast Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-08-07 13:06 -0700
csiph-web