我有一个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("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&)
我不知道,如何修复它。有人能帮助我吗?
答案 0 :(得分:1)
这意味着MUCRoomHandler
中存在您尚未在派生类MucHandler
中实现的纯虚方法。所以,你必须实现它们。您无法使用未实现的成员函数实例化对象。
具体来说,它从MUCRoomHandler
:
virtual void handlerMUCParticipantPresence(MUCRoom*,
MUCRoomParticipant,
const Presence&);
您已经实现了这一点,这是不同的(查看参数列表):
virtual void handleMUCParticipantPresence(MUCRoom * room,
const MUCRoomParticipant participant,
Presence presence){ }
我为了清楚起见删除了gloox
名称空间。
由于handlerMUCParticipantPresence
的实现具有不同的参数类型,因此它不实现纯虚方法。这是错误的来源。
答案 1 :(得分:1)
代码和错误消息之间存在许多细微差别,因此这可能只是一个拼写错误,但在错误消息中,handlerMUCParticipantPresence()
需要Presence&
作为最终参数,您显示的实现只需要Presence
值。如果实际情况如此,那么您没有正确覆盖纯虚方法,因此您无法创建类的实例。