Callbacks wtf?

I'm currently working on a c++ class using a c library.
I've heard that c++ doesn't automatically casts voids
so when i assign my function it gives me a strange error like

error cannot convert void to void O_o

here's my code

1
2
3
4
5
6
7
//headerfile
class IrcBot
{
//removed unuseful things
    //events
    void irc_on_connect(irc_session_t*, const char*, const char*, const char**, unsigned int);
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//CppFile
#include "ircbot.h"

IrcBot::IrcBot(std::string name, std::string server, int port, std::string channel)
{
    memset(&events, 0, sizeof(events));
    events.event_connect =irc_on_connect;
    session = irc_create_session(&events);
}

void IrcBot::irc_on_connect(irc_session_t* session, const char* event, const char* origin, const char** params, unsigned int count)
{
    irc_cmd_join(session, "#lalaa", 0);
    irc_cmd_msg(session, "#lalaa", "Ciao a tutti!");
}


Anddd, here's the error
 
C:\*HueHue*\Documents\Prog\Proj\MrPucchiacco\ircbot.cpp|6|error: cannot convert 'IrcBot::irc_on_connect' from type 'void (IrcBot::)(irc_session_t*, const char*, const char*, const char**, unsigned int) {aka void (IrcBot::)(irc_session_s*, const char*, const char*, const char**, unsigned int)}' to type 'irc_event_callback_t {aka void (*)(irc_session_s*, const char*, const char*, const char**, unsigned int)}'|


Thanks in advance :D
Last edited on
error cannot convert void to void O_o


You might want to re-read that error message. It is saying it cannot convert a member function to a nonmember function (thus the ircBot:: in the one and not in the other.)

It may be sufficient to make IrcBot::irc_on_connect static, provided irc_cmd_join and irc_cmd_msg are not members of IrcBot.
Topic archived. No new replies allowed.