From kde-core-devel Tue Nov 02 07:17:33 1999 From: Don Sanders Date: Tue, 02 Nov 1999 07:17:33 +0000 To: kde-core-devel Subject: Re: KPresenter X-MARC-Message: https://marc.info/?l=kde-core-devel&m=94152944427349 On Tue, 02 Nov 1999, Sirtaj Singh Kang wrote: > On Tue, 2 Nov 1999, Don Sanders wrote: > [snip] > > I'm using static_cast as the programmers FAQ said don't use dynamic_cast > > unless you have to, and I didn't want to use C style casts, as I was under the > > impression that would mean I would burn in hell for all eternity. > > I was under the impression that static_cast and the old C-style cast were > the same? Well static_cast looks damn ugly (it's verbose) which makes it easy to see when you're casting, which might be a good thing as casting tends to be a common source of errors. My paragraph probably should have been terminated with a :-) as I was half joking, I mean static_cast sure is annoying to type, and its advantage pedantic. > When the Programmer's FAQ says "avoid dynamic_cast" (I haven't seen this > FAQ), I would hazard it means "think about why you need the cast at all". > When casting down the inheritance tree (eg casting a QWidget * to > QPopupMenu *), dynamic_cast is the best way to do it. For anything else, > use C-style or static_cast. (except when you are just removing const; then > use const_cast). > > -Taj. That sounds like good advice to me. Hmm, I said FAQ but really I meant the "Practical C++ Programmings Tips" (your tips that is, thanks I found them helpful), in particular the question: "Do you really need dynamic_cast? Currently, many people building KDE with egcs use the -fno-rtti flag since it results in significantly smaller object files and executables. Since dynamic_cast uses RTTI, you should think long and hard about whether you really need to use it in your code, until people are more comfortable with building KDE with RTTI enabled." I figured it was suggesting using some other type of cast. I do need to use some type of cast as I have chosen to use QListView and derive my own types from QListViewItem, (I need to cast from QListViewItem to a derived type). Mind you if we are supporting RTTI now then maybe I should change all my static_casts to dynamic_casts, (not that I'm going to be in a hurry to do that). BFN, Don.