我有gloox Bot。我正在尝试创建MUC房间处理程序,但是现在我在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");
}


但是我有错

无法分配抽象类型“ Muchandler”的对象
因为以下虚拟函数在'MucHandler'中是纯函数
/usr/include/gloox/mucroomhandler.h:107:注意虚拟虚空gloox :: MUCRoomHandler :: handlerMUCParticipantPresence(gloox :: MUCRoom *,gloox :: MUCRoomParticipant,const gloox :: Presence&)

我不知道如何解决它。有谁能够帮助我?

最佳答案

这意味着在MUCRoomHandler中存在纯虚拟方法,而在派生类MucHandler中尚未实现。因此,您必须实现它们。您无法使用未实现的成员函数实例化对象。

具体来说,它在MUCRoomHandler中提到了此方法:

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


您已经实现了这一点,这是不同的(请看参数列表):

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


为了清楚起见,我删除了gloox名称空间。

由于handlerMUCParticipantPresence的实现具有不同的参数类型,因此不会实现纯虚拟方法。这是错误的根源。

关于c++ - 我的gloox bot错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11778644/

10-10 10:19