0

我有 gloox 机器人。我正在尝试创建 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("example3@gmail.com","example3","home");
}

但我有错误

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

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

4

2 回答 2

1

这意味着MUCRoomHandler您没有在派生类中实现纯虚方法MucHandler。因此,您必须实施它们。您不能使用未实现的成员函数来实例化对象。

具体来说,它提到了这种方法MUCRoomHandler

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

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

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

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

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

于 2012-08-02T13:40:55.083 回答
1

代码和错误消息之间存在许多细微差别,因此这可能只是一个错字,但在错误消息中,handlerMUCParticipantPresence()将 aPresence&作为最终参数,而您显示的实现仅采用 aPresence值。如果情况确实如此,那么您没有正确覆盖纯虚拟方法,因此您无法创建类的实例。

于 2012-08-02T13:43:02.377 回答