Re: why do I need ::sin, not std::sin?
From: Alexander Stippler (stip_at_mathematik.uni-ulm.de)
Date: 06/04/04
- Next message: Michiel Salters: "Re: sizeof(char)"
- Previous message: Pete Becker: "Re: why do I need ::sin, not std::sin?"
- In reply to: red floyd: "Re: why do I need ::sin, not std::sin?"
- Next in thread: Victor Bazarov: "Re: why do I need ::sin, not std::sin?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 04 Jun 2004 18:25:32 +0200
red floyd wrote:
> Alexander Stippler wrote:
>
>> Hi,
>>
>> simple question. Why does this not work:
>>
>> #include <algorithm>
>> #include <cmath>
>> #include <iostream>
>>
>> int
>> main()
>> {
>> double a[2];
>> a[0] = 0;a[1] = M_PI/2.;
>> std::transform(a, a+2, a, std::sin);
>> std::cout << a[0] << ", " << a[1] << std::endl;
>> return 0;
>> }
>>
>> for gcc and icc the type of the third argument of transform is unknown.
>> If I use the global ::sin it works fine. Why? I include cmath and there
>> sin is defined in namespace std, so why is it unknown?
>>
>> regards,
>> alex
>>
>
> IANAG (I am not a guru), and am probably way off base (please correct me
> guys -- please no flames).
>
> Isn't std::sin a template? Would you need to specifically instantiate
> std::sin, i.e.
>
> std::transform(a, a+2, a, std::sin<double>)
>
> You might also want to use std::ptr_fun as a wrapper to std::sin (or
std::transform(a, a+2, a, std::sin<double>)
What about this line if you have <complex> included? I took a look at the
<cmath> source code. It defines (in namespace std!) sin for float argument
as non template function, but the example above results in the same error
for float. I'm confused.
regards,
alex
- Next message: Michiel Salters: "Re: sizeof(char)"
- Previous message: Pete Becker: "Re: why do I need ::sin, not std::sin?"
- In reply to: red floyd: "Re: why do I need ::sin, not std::sin?"
- Next in thread: Victor Bazarov: "Re: why do I need ::sin, not std::sin?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|