[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    MORE INFO (Re: What is the difference between dynamic and static_cast)
From:       Thomas Leitner <tom () radar ! tu-graz ! ac ! at>
Date:       2000-11-09 7:33:38
[Download RAW message or body]


O.k. I was talking to my Compaq C++ contact and he came up with this below
(it's a reply from me to him, to avoid confusion) The main question seems
to be:

Is it legal to dynamic_cast from a base_class* to a derived_class* ?

Can anyone comment on this?

Thanks // Tom

On Wed, 8 Nov 2000 cxxc_bugs@cxxc.zko.dec.com wrote:

> void KMFolderTree::doFolderSelected( QListViewItem* qlvi )
> {
>     KMFolderTreeItem* fti = dynamic_cast< KMFolderTreeItem* >(qlvi);
> // Add this
> if (fti==0)
> printf("type of qlvi is %s value of qlvi %p\n",typeid(qlvi).name(),qlvi);
>
> and send back the output.

This is the output:

type of qlvi is QListViewItem * value of qlvi 140135560

Which looks perfectly legal since KMFolderTreeItem is directly derived
from QListViewItem.

> From what I can recreate from the .ixx file, the class hierarchy
> looks like this:
>
> struct Qt {};
> struct QListViewItem: public Qt
> {
>     virtual ~QListViewItem() {;}
> };
> class KMFolderTreeItem : public QListViewItem {};
> class  QCheckListItem : public QListViewItem {};
>
> If qlvi is of type QListViewItem* then I would expect the cast
> to fail because you are trying to cast a Base* to a Derived*
> not vice versa.

This seems to be the main problem. Apparently this is legal in G++
but illegal in cxx.

> If qlvi is of type QCheckListItem, then I would
> expect it to fail because QCheckListItem is not derived from
> KMFolderTreeItem. The only way I can imagine the cast
> succeeding is if qlvi was of type KMFolderTreeItem.
> But I could not come up with a reproducer that showed different
> behaviour on g++ than cxx, no matter what type I made qlvi.
> Maybe you're using a different version of g++?

There are many different g++ versions used because this very same code
is in the KDE 2.0 release which was already compiled for many different
platforms including Solaris, FreeBSD and various Linux versions. Tru64/CXX
is the only platform where this fails.

Thanks // Tom
-- 
--------------------------------------------------------------------------
Dr. Tom Leitner                             Dept. of Communications
                                            Graz University of Technology,
e-mail    : tom@radar.tu-graz.ac.at         Inffeldgasse 12
Phone     : +43-316-873-7455                A-8010 Graz / Austria / Europe
Fax       : +43-316-463-697
Home page : http://wiis.tu-graz.ac.at/people/tom.html
PGP public key on : ftp://wiis.tu-graz.ac.at/pgp-keys/tom.asc or send
mail with subject "get Thomas Leitner" to pgp-public-keys@keys.pgp.net
--------------------------------------------------------------------------
    Before we have the paperless office, we have the paperless toilet!

 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic