I have a factory class supposed to construct objects of classes derived from a base class. The concrete instance is identified by a QString. I want to use a QMap (or similar) to map the QString to a member function pointer, but i get an error.
I tried various syntax variants, most of them found somewhere here in this forum.
#include "messagefactory.h"
#include "alivecheckmessage.h"
namespace MES {
QMap<QString, Message (MessageFactory::*)(void)> MessageFactory::messageMap;
MessageFactory::MessageFactory()
{
// Nothing, is private
}
Message MessageFactory::createAliveCheckMessage() {
AliveCheckMessage msg;
return msg;
}
Message MessageFactory::createMessage(QString id) {
if (messageMap.isEmpty()) {
messageMap[AliveCheckMessage::ID] = &createAliveCheckMessage;
}
}
}
The error is in the last line. The error message says:
error: assigning to 'MES::Message (MES::MessageFactory::*)()' from incompatible type 'MES::Message (\*)()'
How am i supposed to correct that?