相关疑难解决方法(0)

如何存储可变参数模板参数?

是否可以以某种方式存储参数包供以后使用?

template <typename... T>
class Action {
private:        
    std::function<void(T...)> f;
    T... args;  // <--- something like this
public:
    Action(std::function<void(T...)> f, T... args) : f(f), args(args) {}
    void act(){
        f(args);  // <--- such that this will be possible
    }
}
Run Code Online (Sandbox Code Playgroud)

然后是:

void main(){
    Action<int,int> add([](int x, int y){std::cout << (x+y);}, 3, 4);

    //...

    add.act();
}
Run Code Online (Sandbox Code Playgroud)

c++ variadic-templates c++11

79
推荐指数
3
解决办法
3万
查看次数

标签 统计

c++ ×1

c++11 ×1

variadic-templates ×1