Ashley Cusack
Ashley Cusack

Reputation: 63

c++ template within class

I have a function within a class that is passed a function and its parameters, it then binds them into a function call and calls the function among others things.

This has been hacked together quickly to test a concept i know the code isn't great.

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;
}

I get this error

Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Any help really appreciated.

Upvotes: 0

Views: 63

Answers (1)

user7881131
user7881131

Reputation:

You are missing a return type for your function.

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

Since you don't return anything in the function, void would be the appropriate return type.

Upvotes: 3

Related Questions