Storing function pointer in std::function

前端 未结 3 741
囚心锁ツ
囚心锁ツ 2021-02-07 15:55

I\'m trying to write a C++0x wrapper around dlopen()/dlsym() to dynamically load functions from shared objects:

class DynamicLoader
{
  public:
    DynamicLoade         


        
3条回答
  •  太阳男子
    2021-02-07 16:25

    try this:

    static_cast()
    

    seems works in VC10

    complete test:

    #include 
    
    void test()
    {}
    
    template 
    std::function cast(void* f)
    {
        return static_cast(f);
    }
    
    int main()
    {
        std::function f = cast(&test);
        return 0;
    }
    

提交回复
热议问题