C++ - Перегрузка оператора вызова шаблонной функции - Ошибка C2064

Я пытаюсь перегрузить оператор вызова функции в C++, и я получил эту ошибку компиляции, которую я не могу устранить (Visual Studio 2010).

Ошибка в строке 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;
}

1 ответ

Решение

act - это указатель, вы должны сначала разыменовать его, например, так:

(*act)(4);
Другие вопросы по тегам