Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #25833

Re: Java vs C++

From Thomas Richter <thor@math.tu-berlin.de>
Newsgroups comp.lang.java.programmer
Subject Re: Java vs C++
Date 2011-02-07 14:57 +0100
Organization InterNetNews at News.BelWue.DE (Stuttgart, Germany)
Message-ID <iiotom$2ml$1@news.belwue.de> (permalink)
References (7 earlier) <4d4f042b$0$23753$14726298@news.sunsite.dk> <iincuv$ot9$1@news.belwue.de> <iineik$3tp$10@lust.ihug.co.nz> <iinft1$95e$1@speranza.aioe.org> <iinjr9$7j3$10@lust.ihug.co.nz>

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

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

csiph-web