-3
struct Functor
{
public:
    template <typename... argtypes>
    Functor(std::function<void()> Function)
    {
        this->Function = Function;
    }

    ~Functor() {}

    void operator()() const
    {
        OutputDebugStringA("Hello there, General Kenobi");
        Function();
    }

private:
    std::function<void()> Function;
};

void gtk()
{
    OutputDebugStringA("What is happening to meeee");
}
Functor Draw = Functor(&gtk);
void foo() { Draw(); }

How can I make Functor's std::function accept Argument Types? I tried the following:

Functor(std::function<void(argtypes...)> Function)
Functor Draw = Functor<void>(&gtk);

But the compiler complains about 'typename not allowed'.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
Swagov3rflow
  • 25
  • 1
  • 8
  • 2
    Please post a [mcve] that reproduces the error – Praetorian Jan 25 '18 at 20:44
  • @Praetorian That is a complete example. – Swagov3rflow Jan 25 '18 at 20:45
  • 2
    No, it isn't. Besides missing header includes and `OutputDebugStringA` which is OS specific, the example as posted does compile. You should post the version that reproduces the error message. If you're asking what I think you're asking, the answer is *a function pointer is not the same as `std::function`* – Praetorian Jan 25 '18 at 20:50
  • 1
    No, it isn't: a complete example require a `main()` and the includes – max66 Jan 25 '18 at 20:50

1 Answers1

1

You need to make Functor itself a template, rather than just its constructor. The parameters are part of the calling convention and are thus needed at a wider scope than just the ctor. The std::function member also needs the argument types and you also need them when actually invoking the stored callable.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23