C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Typumwandlungen

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Martin Heibel
Guest





PostPosted: Wed May 05, 2004 7:59 pm    Post subject: Re: Typumwandlungen Reply with quote



Christian Banse wrote:

Quote:
Das geht auch in C++ nicht. Du würdest einen Segmentation Fault oder
Bus Error bekommen und tagelang danach suchen! Dein Problem ist
unabhängig von der Programmiersprache.

Kleines Gegenbeispiel:

class Animal {
public:
void MakeSound( ) { printf( "(nothing)n" ); }
};

class Cow : public Animal {
public:
void MakeSound( ) { printf( "mOooOn" ); }
};

int main( ) {
Animal* animal = new Animal( );
Cow* cow = (Cow*) animal;
Das ist keine Typwandlung, sondern Dummfug.


Quote:
cow->MakeSound( );
animal->MakeSound( );
}

hoth:~# g++ animal.cpp -o animal
hoth:~# ./animal
mOooO
(nothing)
Die meisten C++-Compiler erzeugen aus diesem Beispiel Code der funktioniert,

weil Du nicht auf Daten des Objekts zugreifst, aber hier sind Probleme
vorprogrammiert. Wer so etwas in einem ernsthaften Projekt macht, ist in
meinen Augen ein Saboteur, denn das ist bösartig.

Quote:
Die ClassCastException in Java besagt, das Dein Objekt eben KEIN
MyDocument ist. Darum kannst Du es auch nicht umwandeln. Wäre es eins,
versteckt hinter der Maske eines Document, würde die Umwandlung auch
funktionieren.
Das ist eines der Java-Features, die Java-Anwendungen i.Allg. langsamer aber

robuster machen als C++-Anwendungen.

Quote:
Ich werde das Gefühl nicht los, Du hast ein par grundlegende
Mechanismen der objektorientierten Programmierung noch nicht
verstanden...

Ich werde das Gefühl nicht los, dass du noch keine einzige Zeile C++-Code
geschrieben hast Smile
Es ist offensichtlich, dass Du nicht weißt, was Du tust.


F'up2 de.comp.lang.iso-c++

Gruß,
Martin

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.