调用函数不同参数以及返回值

来源:互联网 发布:linux 清空回收站 编辑:程序博客网 时间:2024/04/30 05:10
template<typename T>
class CTC
{
public:
    CTC(std::function<T> f)
    {
        fu = f;
    }

    template<typename...Args>
    void Exec(Args&&...args)
    {
        fu(std::forward < Args>(args)...);
    }

private:
    std::function<T> fu;
};

void Test1()
{
    std::cout << "test1" << endl;
}

void Test2(int a)
{
    std::cout << "test1" <<a<< endl;
}

int Test3(int a,int b)
{
    return 0;
}

int main()
{
    CTC<int(int,int)> t(Test3);
    t.Exec(1,2);

    getchar();

}

0 0