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: Komplexe Zahlen - warum geht das nicht?

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





PostPosted: Mon Apr 11, 2005 10:51 pm    Post subject: Re: Komplexe Zahlen - warum geht das nicht? Reply with quote



Ottmar Ohlemacher wrote:

Quote:
Hi,

Warum geht das nicht?

Folgendes Program sei gegeben:

#include<iostream
#include #include using namespace std;
int main()
{
complex
a1 = a1 + (2.2, 3.1);

Weil (2.2, 3.1) kein Objekt der Klasse complex<float> ist. Stattdessen ist
es äquivalent zu 3.1.
Versuch mal:

a1 = a1 + complex<float>(2.2, 3.1);

Quote:
cout << a1;

getchar();

}

--
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
Ozan Ayyüce
Guest





PostPosted: Mon Apr 11, 2005 11:34 pm    Post subject: Re: Komplexe Zahlen - warum geht das nicht? Reply with quote



Ottmar Ohlemacher:

Quote:
a1 = a1 + (2.2, 3.1);

Du weist dort a1 die Summe von a1 und dem Rückgabewert des ,-operators
zu. Dieser ist immer der Wert hinter dem ',', hier also 3.1. Obige Zeile
ist also äquivalent zu a1 = a1 + 3.1;

Die Klasse complex hat einen +-operator, der als Argument einen Wert vom
typ float akzeptiert. So wird kein Objekt des Typs complex benötigt und
es entsteht kein Fehler, das Ergebnis ist jedoch nicht wie von dir
erwartet.

Du musst also den compiler ausdrücklich anweisen, ein Objekt des Typs
complex zu erzeugen. Um dies innerhalb eines Ausdrucks zu tun brauchst
du nur den contructor mit passenden Argumenten aufzurufen:

a1 = a1 + complex<float>(2.2, 3.1);

Ozan

--
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.