Hi, I have a problem with template in which I use QMap:
template
<
class IdentifierType,
class BytesToRead
>
class CommandHandler : public Command
{
public:
explicit CommandHandler();
~CommandHandler();
static bool registerCommand(const IdentifierType& identifier, Command* ptrToObject);
static bool unregisterCommand(const IdentifierType& identifier);
QPair<ResponseType
::type, QByteArray> handleMessage
(QByteArray* datagramPtr
);
private:
static QMap<IdentifierType, Command*> _associations;
};
template
<
class IdentifierType,
class BytesToRead
>
class CommandHandler : public Command
{
public:
explicit CommandHandler();
~CommandHandler();
static bool registerCommand(const IdentifierType& identifier, Command* ptrToObject);
static bool unregisterCommand(const IdentifierType& identifier);
QPair<ResponseType::type, QByteArray> handleMessage(QByteArray* datagramPtr);
private:
static QMap<IdentifierType, Command*> _associations;
};
To copy to clipboard, switch view to plain text mode
template <class IdentifierType, class BytesToRead>
bool
CommandHandler<IdentifierType, BytesToRead>
::registerCommand(const IdentifierType& identifier, Command* ptrToObject)
{
if(_associations.contains(identifier))
return 0;
else
{
_associations.insert(identifier, ptrToObject);
return 1;
}
}
template <class IdentifierType, class BytesToRead>
bool
CommandHandler<IdentifierType, BytesToRead>
::registerCommand(const IdentifierType& identifier, Command* ptrToObject)
{
if(_associations.contains(identifier))
return 0;
else
{
_associations.insert(identifier, ptrToObject);
return 1;
}
}
To copy to clipboard, switch view to plain text mode
namespace TransportLayerType {
enum type{
V1 = 1
};
}
typedef CommandHandler<TransportLayerType::type, quint8> TransportLayerHandler;
namespace TransportLayerType {
enum type{
V1 = 1
};
}
typedef CommandHandler<TransportLayerType::type, quint8> TransportLayerHandler;
To copy to clipboard, switch view to plain text mode
And when I try to do this:
TransportLayerHandler::registerCommand(TransportLayerType::V1, new TransportLayerV1());
TransportLayerHandler::registerCommand(TransportLayerType::V1, new TransportLayerV1());
To copy to clipboard, switch view to plain text mode
I get:
undefined reference to `CommandHandler<TransportLayerType::type, unsigned char>::_associations'
Do you have any ideas?
Thanks for help, Marcin.
Bookmarks