Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25488 > unrolled thread
| Started by | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| First post | 2011-02-07 15:02 +1300 |
| Last post | 2011-02-07 14:57 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:02 +1300
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-08 16:15 +1300
Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-07 14:57 +0100
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 15:02 +1300 |
| Subject | Re: Java vs C++ |
| Message-ID | <iinjr9$7j3$10@lust.ihug.co.nz> |
In message <iinft1$95e$1@speranza.aioe.org>, javax.swing.JSnarker wrote: > On 06/02/2011 7:32 PM, Lawrence D'Oliveiro wrote: > >> In message<iincuv$ot9$1@news.belwue.de>, Thomas Richter wrote: >> >>> There is no "ClassCastException" in C++. >> >> Yes there is. It’s called “bad_cast”. Where do you think Java got the >> idea from? > > dynamic_cast<foo>(bar) can throw this if bar is not really a foo. But > C++ lets you use the unsafe old (foo)bar cast from C, and if bar is not > really a foo, welcome to undefined behaviorville. The fact remains, there IS an equivalent to ClassCastException in C++.
[toc] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-08 16:15 +1300 |
| Message-ID | <iiqcgk$qt4$4@lust.ihug.co.nz> |
| In reply to | #25488 |
In message <iiotom$2ml$1@news.belwue.de>, Thomas Richter wrote: > Lawrence D'Oliveiro wrote: > >> In message <iinft1$95e$1@speranza.aioe.org>, javax.swing.JSnarker wrote: >> >>> On 06/02/2011 7:32 PM, Lawrence D'Oliveiro wrote: >>> >>>> In message<iincuv$ot9$1@news.belwue.de>, Thomas Richter wrote: >>>> >>>>> There is no "ClassCastException" in C++. >>>> >>>> Yes there is. It’s called “bad_cast”. Where do you think Java got the >>>> idea from? >>>> >>> dynamic_cast<foo>(bar) can throw this if bar is not really a foo. But >>> C++ lets you use the unsafe old (foo)bar cast from C, and if bar is not >>> really a foo, welcome to undefined behaviorville. >> >> The fact remains, there IS an equivalent to ClassCastException in C++. > > The fact remains that this is irrelevant to the discussion. The fact remains, the poster said “There is no "ClassCastException" in C++”, which I understood to mean “There is no equivalent to "ClassCastException" in C++”, which is wrong. > Templates aren't used like this in C++ ... Templates are orthogonal to the business of class casts. > ... and the C++ compiler doesn't insert a type check into the binary to > see whether the types match. It does for the C++ equivalent to the Java subclass cast. > Besides, dynamic_cast<> only throws if the involved objects have virtual > functions, and thus have run time type information available, and the > types are not compatible. I went over section 5.2.7 “Dynamic cast” of the C++ standard very carefully, and I can find no such proviso. It’s only a page and a half, so I think it’s unlikely I missed anything. Have a look for yourself and see if I’m right or wrong.
[toc] | [prev] | [next] | [standalone]
| From | Thomas Richter <thor@math.tu-berlin.de> |
|---|---|
| Date | 2011-02-07 14:57 +0100 |
| Message-ID | <iiotom$2ml$1@news.belwue.de> |
| In reply to | #25488 |
Lawrence D'Oliveiro wrote: > In message <iinft1$95e$1@speranza.aioe.org>, javax.swing.JSnarker wrote: > >> On 06/02/2011 7:32 PM, Lawrence D'Oliveiro wrote: >> >>> In message<iincuv$ot9$1@news.belwue.de>, Thomas Richter wrote: >>> >>>> There is no "ClassCastException" in C++. >>> Yes there is. It’s called “bad_cast”. Where do you think Java got the >>> idea from? >> dynamic_cast<foo>(bar) can throw this if bar is not really a foo. But >> C++ lets you use the unsafe old (foo)bar cast from C, and if bar is not >> really a foo, welcome to undefined behaviorville. > > The fact remains, there IS an equivalent to ClassCastException in C++. The fact remains that this is irrelevant to the discussion. Templates aren't used like this in C++, and the C++ compiler doesn't insert a type check into the binary to see whether the types match. The type check is done at compile time. Besides, dynamic_cast<> only throws if the involved objects have virtual functions, and thus have run time type information available, and the types are not compatible. It thus also works quite different. Greetings, Thomas
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web