search

Home  >  Q&A  >  body text

在C++中如何使用多态的容器?

比如我想使用一个存放可调用对象的容器,可以同时容纳匿名函数,仿函数,函数指针和std::function,如何实现呢?

PHP中文网PHP中文网2806 days ago543

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 11:48:30

    You just use std::function to wrap it up. As long as the call signatures of these anonymous functions, functors, function pointers and the like are the same, you can use std::function to save them and put them in a container. .

    reply
    0
  • 阿神

    阿神2017-04-17 11:48:30

    Use Boost.Any, a generic container
    http://www.boost.org/doc/libs/1_57_0/doc/html/any.html

    reply
    0
  • Cancelreply