2

Error:

C:\testa\game.cpp|147|error: no matching function for call to 'game::register_handler(PacketFamily, PacketAction, 
<unresolved overloaded function type>)'|

Heres part of the code since it's too big.

I had to typedef handler_callback inside class game otherwise one of the two would be undefined for the other.

game.h

class game
{
typedef bool (game::*handler_callback)(PacketReader  reader);
public:
bool default_handler_init (PacketReader reader);
void register_default_handlers();
void register_handler(PacketFamily family, PacketAction action,handler_callback        callback);
};

game.cpp

 void game::register_default_handlers()
{
    register_handler(PACKET_F_INIT, PACKET_A_INIT,default_handler_init);

}

void game::register_handler(PacketFamily family, PacketAction action,handler_callback     callback)
{
handlers.insert(std::make_pair(std::make_pair(family, action), callback));
}
10
  • 1
    post a small complete example as well as complete error me Commented Aug 14, 2014 at 3:08
  • Where is line 147? Commented Aug 14, 2014 at 3:09
  • it's deleting the last part of my error Commented Aug 14, 2014 at 3:11
  • 2
    @user3810737 - Compiles with no errors: ideone.com/QFyAtY Commented Aug 14, 2014 at 3:19
  • 1
    Maybe you're missing an ampersand. register_handler(PACKET_F_INIT, PACKET_A_INIT, &default_handler_init); Commented Aug 14, 2014 at 3:20

1 Answer 1

1

I expanded the OP's code to the following so that it would compile:

class PacketReader {};
class PacketFamily {};
class PacketAction {};
const PacketFamily PACKET_F_INIT;
const PacketAction PACKET_A_INIT;

class game
{
    typedef bool (game::*handler_callback)(PacketReader  reader);
public:
    bool default_handler_init (PacketReader reader);
    void register_default_handlers();
    void register_handler(PacketFamily family, PacketAction action, handler_callback callback);
};

void game::register_default_handlers()
{
    register_handler(PACKET_F_INIT, PACKET_A_INIT, default_handler_init);
}

void game::register_handler(PacketFamily family, PacketAction action, handler_callback callback)
{
    //handlers.insert(std::make_pair(std::make_pair(family, action), callback));
}

Compiling with g++ using the command g++ -c -Wall -std=c++11 test.cpp yields the following errors:

test.cpp: In member function ‘void game::register_default_handlers()’:
test.cpp:18:71: error: no matching function for call to ‘game::register_handler(const PacketFamily&, const PacketAction&, <unresolved overloaded function type>)’
     register_handler(PACKET_F_INIT, PACKET_A_INIT,default_handler_init);
                                                                   ^
test.cpp:18:71: note: candidate is:
test.cpp:13:10: note: void game::register_handler(PacketFamily, PacketAction, game::handler_callback)
     void register_handler(PacketFamily family, PacketAction action,handler_callback callback);
          ^
test.cpp:13:10: note:   no known conversion for argument 3 from ‘<unresolved overloaded function type>’ to ‘game::handler_callback {aka bool (game::*)(PacketReader)}’

Anyway, to fix the problem, add &game:: to the call to register_handler:

register_handler(PACKET_F_INIT, PACKET_A_INIT,&game::default_handler_init);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.