1

I'm trying to overload function call operator in c++ and I got this compilation error that I cannot resolve (Visual Studio 2010).

Error is in line act(4);

#include <stdio.h>
#include <iostream>

void Test(int i);
template <class T> class Action
{
    private:
        void (*action)(T);
    public:
        Action(void (*action)(T))
        {
            this->action = action;
        }
        void Invoke(T arg)
        {
            this->action(arg);
        }
        void operator()(T arg)
        {
            this->action(arg);
        }
};

int main()
{
    Action<int> *act = new Action<int>(Test);
    act->Invoke(5);
    act(4);     //error C2064: term does not evaluate to a function taking 1 arguments overload
    char c;
    std::cin >> c;

    return 0;
}

void Test(int i)
{
    std::cout << i;
}
EOG
  • 1,677
  • 2
  • 22
  • 36
  • 1
    By the way, `#include ` is completely useless here as you never use it, and is superseded by `` anyway. – chris Sep 20 '12 at 21:19

1 Answers1

8

act is stil a pointer you have to dereference it first, like so:

(*act)(4);
Borgleader
  • 15,826
  • 5
  • 46
  • 62