Search code examples
c++botschatroomgloox

I have mistake in my gloox bot


I have gloox Bot. I'm trying to create MUC room handler, but now I have mistake, when I compile it under gcc.

class MucHandler : public MUCRoomHandler {
private:
    Client *client;
public:
    MucHandler(Client *cl){
        client = cl;
    }

    virtual void handleMUCMessage (MUCRoom *room, const Message &msg, bool priv){
    }
    virtual bool handleMUCRoomCreation( MUCRoom *room )
    {
    }
    virtual void handleMUCSubject( MUCRoom * /*room*/, const std::string& nick, const std::string& subject )
    {
    }
    virtual void handleMUCInviteDecline(MUCRoom*, const JID& invitee, const string& reason){
    }
    virtual void handleMUCError(MUCRoom*, StanzaError error ){
    }
    virtual void handleMUCInfo( MUCRoom * /*room*/, int features, const std::string& name, const DataForm* infoForm )
    {
    }

    virtual void handleMUCItems( MUCRoom * /*room*/, const Disco::ItemList& items )
    {
    }
    virtual void handleMUCParticipantPresence(MUCRoom * room, const MUCRoomParticipant participant,Presence     presence){

    }   
};


class Bot {
private:
    Client *client;
    MUCRoom *room;
    MucHandler *muc;
public:
    Bot(string login, string password, string resource){
        const string fullJidName = login + '/' + resource;
        JID jid(fullJidName);
        //mucroom
        const string server = "conference.jabber.ru";
        const string uName = jid.username();
        const string roomJid = uName + "@" + server + "/" + uName;
        JID roomJID( roomJid );

        client = new Client(jid,password);
        client->setPresence( Presence::Available, -1 );

        //mucRoom handler 
        muc = new MucHandler(client);
        room = new MUCRoom( client, roomJID, muc, 0 );
        //room->registerMUCRoomHandler(muc);
        //

        client->connect();
    }
    ~Bot(){
        delete client;
        delete room;
    }

    void joinRoom(){
        room->join();
        room->getRoomInfo();
        room->getRoomItems();
    }

    void setRoomNick(const string& nick){
        room->setNick(nick);
    }
    void invite(const string& inv, const string& reason)
    {
        JID invitee(inv);
        room->invite(invitee, reason);
    }
};

int main(int argv, char** argc){
    Bot bot("[email protected]","example3","home");
}

But I have mistake

cannot allocate an object of abstract type 'Muchandler' because the following virtual function are pure within 'MucHandler' /usr/include/gloox/mucroomhandler.h:107: note virtual void gloox::MUCRoomHandler::handlerMUCParticipantPresence(gloox::MUCRoom*, gloox::MUCRoomParticipant, const gloox::Presence&)

I have no idea, how to fix it. Can anybody help me?


Solution

  • It means that there are pure virtual methods in MUCRoomHandler that you have not implemented in the derived class MucHandler. So, you have to implement them. You cannot instantiate an object with unimplemented member functions.

    Specifically, it mentions this method from MUCRoomHandler:

    virtual void handlerMUCParticipantPresence(MUCRoom*,
                                               MUCRoomParticipant, 
                                               const Presence&);
    

    You have implemented this, which is different (look at the parameter list):

    virtual void handleMUCParticipantPresence(MUCRoom * room, 
                                              const MUCRoomParticipant participant,
                                              Presence presence){ }   
    

    where I have removed the gloox namespaces for clarity.

    Since your implementation of handlerMUCParticipantPresence has different argument types, it doesn't implement the pure virtual method. This is the source of the error.