小编Pet*_*ter的帖子

std :: function与标准函数

我正在使用函数指针std :: function, 并遇到了以下问题.

让我们考虑下面的代码:

#include <cmath>
#include <functional>

// g++ -std=c++17 SF.C -o SF
// clang++ -std=c++17 SF.C -o SF

int main()
{
    typedef double (*TpFunctionPointer)(double) ;

    TpFunctionPointer pf1 = sin;                     // o.k.
    TpFunctionPointer pf2 = std::sin;                // o.k
    TpFunctionPointer pf3 = std::riemann_zeta;       // o.k

    std::function< double(double) > sf1( sin );                // o.k
    std::function< double(double) > sf2( std::sin );           // fails
    std::function< double(double) > sf3( std::riemann_zeta );  // fails
}
Run Code Online (Sandbox Code Playgroud)

用函数指针pf1,pf2,pf3和sf1 编译g++ v8.2clang …

c++ std c++17

0
推荐指数
1
解决办法
121
查看次数

标签 统计

c++ ×1

c++17 ×1

std ×1