How do I refer to std::sin(const valarray &)?

后端 未结 3 467
故里飘歌
故里飘歌 2020-12-19 08:18

I\'m having trouble with some valarray function pointer code:

double (*fp)(double) = sin;
valarray (*fp)(const valarray &) =          


        
3条回答
  •  没有蜡笔的小新
    2020-12-19 09:04

    You speak about std::sin in the title, but then assign ::sin.

    valarray (*fp)(const valarray &) = std::sin;
    

    That should work. Note, that you should qualify all uses of sin, though most implementations will inject the name to the global namespace even if you include (that is non-standard behavior).

    Edit: unfortunately, you're out of luck. The standard says about sin(valarray const &) the following (26.3.3.3).

    This function shall return a value which is of type T or which can be unambiguously converted to type T.

    Optimizations performed by gcc are granted by the standard. The code above is not guaranteed to work.

提交回复
热议问题