课堂内的C 模板

c++ template within class

本文关键字:模板 课堂      更新时间:2023-10-16

我在通过一个函数及其参数的类中具有一个函数,然后将它们绑定到函数调用中,并调用函数。

这已经很快被黑客入侵,以测试一个我知道代码不好的概念。

class Profiling {
public: 
    template<class _Fn, class... _Args> GetProfile(_Fn&& _Fx, _Args&&... _Ax);
    int GetTime();
    char Type;
    int Size;
private:
    int StartTime;
    int EndTime;
};
template<class _Fn, class... _Args> Profiling::GetProfile(_Fn&& _Fx, _Args&&... _Ax)
{
    StartTime = clock();
    function<void()> f = _STD bind(_Decay_copy(_STD forward<_Fn>(_Fx)), _Decay_copy(_STD forward<_Args>(_Ax))...);
    f();
    EndTime = clock();
}
int Profiling::GetTime() {
    return EndTime - StartTime;
}

我得到此错误

错误2错误c4430:缺少类型指定符 - 假定int。注意:C 不支持Default-Int

任何帮助都非常感谢。

您缺少函数的返回类型。

template<class _Fn, class... _Args>
/* return type here */ GetProfile(_Fn&& _Fx, _Args&&... _Ax);

由于您不返回该功能中的任何内容,因此void将是适当的返回类型。