From 1742738864381638850
X-Google-Thread: 7894ca11fe,421cd8b98acf7c5
X-Google-Attributes: gid7894ca11fe,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII
Path: g2news2.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 26 Oct 2009 15:30:08 -0500
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
To: (Usenet)
From: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Newsgroups: comp.std.c++
Subject: Re: Why there are both complex::real and std::real?
Organization: http://groups.google.com
Sender: cppmods@cs.rpi.edu
Approved: austern@google.com
Message-ID: <ab16ddac-9dbf-4d57-9c9e-bdfddb9839ed@12g2000pri.googlegroups.com>
References: <210ca399-bea2-47bf-b614-f4cef8fe25fd@k26g2000vbp.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
X-Original-Date: Mon, 26 Oct 2009 12:13:19 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Date: Mon, 26 Oct 2009 15:26:52 CST
Lines: 34
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-c3Xcrh8BNleZZ2+wkXK/m4nDWywH4cgTIWP4VL/KcIVygVlcKATJqXC0Pj8QfPMMpsPtgT8nALUc25v!8lVkLLy+DEAhkgG74oqG9OkrVyPwWBUOBCJI0ysuMgfjarzWAuGPPsURfKG5V5UrstimLNltkNLh!L94zBD8+xixdGTg5numia3/qKw==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Xref: g2news2.google.com comp.std.c++:1577

On 26 Okt., 20:14, Saeed Amrollahi <amrollahi.sa...@gmail.com> wrote:
> I have a question about complex numbers in standard library. Why there
> are both complex::real/imag
> member functions and std::real/imag global funcctions? consider:
> complex<double> cd(1,2);
> double r = cd.real();
> r = real(cd);
> double i  = cd.imag();
> i = imag(cd);
>
> >From point of OO view, it is obvious the real() and imag() should be
>
> part of member functions.
> What is the benefit of global ones?

The member functions are natural for a language with classes, like
C++, therefore the member functions exist. The free function real
and imag exist to match the free functions of C99 in their *generic*
forms from 7.22 <tgmath.h>. With C++0x on all generic C99 complex
functions will have a pendant in <complex> (Nearly all: fabs is
missing
because of LWG defect 595).

HTH & Greetings from Bremen,

Daniel Kr�gler


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



