1. 程式人生 > >c++ 不定引數模板, 待續

c++ 不定引數模板, 待續

1.使用不定引數, 實現c++反射, 初步

#include <boost/any.hpp>
#include <map>
#include <iostream>

class test{
public:
    void add(int i){
        std::cout << i << "addd \n";
    }

};


template <typename R1, typename Member>
struct vatable{
//    typedef decltype(Member) elem;
    vatable(R1 r1, Member m):_this(r1), _m(m){

    }

    template <typename ...ARGS>
    void operator()(ARGS ...args){
        (_this.*_m)(std::forward<ARGS...>(args...));
    }

private:
    R1 _this;
    Member _m;
//    ARGS _args;

};

int main()
{
    test tt;
    vatable<test, decltype(&test::add)> kk(tt, &test::add);

    kk(1);

    return 0;
}