0

While I trying compile my very old game source, I got this error below:

game.h:497:16: error: expression cannot be used as a function
       (_f2)(arg);
                ^
make: *** [Makefile:20: actions.o] Error 1

This is my game.h file:

template<class ArgType>
class TCallList : public SchedulerTask{
public:
    TCallList(
        boost::function<bool(Game*, ArgType)> f1,
        Task* f2,
        std::list<ArgType>& call_list,
        int64_t interval) :
            _f1(f1), _f2(f2), _list(call_list), _interval(interval)
    {
        //
    }
    
    virtual void operator()(Game* arg)
    {
        if(_eventid != 0){
            bool ret = _f1(arg, _list.front());
            _list.pop_front();

            if(ret){
                if(_list.empty()){
                    //callback function
                    if(_f2){
                        (_f2)(arg);
                        delete _f2;
                    }
                }
                else{
                    //fire next task
                    SchedulerTask* newTask = new TCallList(_f1, _f2, _list, _interval);
                    newTask->setTicks(_interval);
                    newTask->setEventId(this->getEventId());
                    arg->addEvent(newTask);
                }
            }
        }
    }

My tasks.h example:

public:
    Task(boost::function1<bool, Game*> f) :
        _f(f)
    {
        //
    }

    virtual ~Task()
    {
        //
    }

    virtual void operator()(Game* arg)
    {
        _f(arg);
    }

My operation system is latest Debian 10 with updates.

Edit:

My source available on github: https://github.com/anyeor/oldsrc

The Ether
  • 1
  • 1
  • 4
    `_f2` is a pointer. Unless there exists some overload or it is an alias for a function pointer, it is unlikely that the pointer is callable – smac89 Sep 27 '21 at 01:05
  • 1
    Show us the definition of `Task` – Jeffrey Sep 27 '21 at 01:07
  • Should it be `(*_f2)(arg);`? – 273K Sep 27 '21 at 01:24
  • what's `Task`? Questions must be self-contained because if the external link rots then it'll become invalid. You need to create a [mcve] and show it here – phuclv Sep 27 '21 at 01:28
  • After changed to `(*_f2)(arg);` i got this error: `game.h:497:17: error: no match for call to ‘(Task) (Game*&)’` – The Ether Sep 27 '21 at 01:29
  • I don't know which file i have to past here @phuclv – The Ether Sep 27 '21 at 01:30
  • @S.M. if `Task` is a function pointer then it can be called directly or with any number of `&`s and `*`s: `_f2(arg)`, `****_f2(arg)`, `*&&****&&&&*****_f2(arg)` all works [Why do function pointer definitions work with any number of ampersands '&' or asterisks '*'?](https://stackoverflow.com/q/6893285/995714) – phuclv Sep 27 '21 at 01:32
  • 1
    @TheEther obviously you don't paste everything here, and no one would click that link and open every file either. Read about [mcve] and http://sscce.org/ to see how to create them. If people don't know what `Task` is how can we answer this? – phuclv Sep 27 '21 at 01:33
  • @phuclv Don't say me your guess, Task can be an object with the operator(). The error says definitely, Task is not a function pointer. – 273K Sep 27 '21 at 01:42
  • @S.M. Sure. Now i did paste the fragment of tasks.h for example. – The Ether Sep 27 '21 at 01:50

1 Answers1

0

Your game.h does not #include "tasks.h", only has the forward declaration class Task;. If you add include, the call (*_f2)(arg); must work. _f2->operator()(arg); also must work.

273K
  • 29,503
  • 10
  • 41
  • 64
  • When i changed it, i got those errors: https://pastebin.com/HZcwmWJS (Never paste expiration). – The Ether Sep 27 '21 at 01:56
  • You got the circular includes. Move `TCallList` to a separate file calllist.h, or move the implementations from tasks.h to tasks.cpp. – 273K Sep 27 '21 at 02:01