C++ method name as template parameter

前端 未结 2 1524
醉酒成梦
醉酒成梦 2020-12-24 13:52

How do I make the method name (here some_method) a template parameter?

template
void sv_set_helper(T& d, bpn::array const&         


        
2条回答
  •  没有蜡笔的小新
    2020-12-24 14:47

    Here is a simple example...

    #include 
    
    template
    void bar(T& d, FType f) {
      (d.*f)(); // call member function
    }
    
    
    struct foible
    {
      void say()
      {
        std::cout << "foible::say" << std::endl;
      }
    };
    
    int main(void)
    {
      foible f;
      bar(f,  &foible::say); // types will be deduced automagically...
    }
    

提交回复
热议问题