From 8248f2912454229f4ded72b8fb4db3e76ea3ad15 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 2 Nov 2016 00:00:55 +0200 Subject: [PATCH] Move the definition of PacketTypeDef::class_id to a separate header Defining it in protocol.h may cause multiple definitions to appear across the program and there are cases where they don't get collapsed to one. DLLs on Windows are one such case. The _impl header is to be included in files that add packet definitions to a protocol and nowhere else. --- source/net/communicator.cpp | 1 + source/net/protocol.cpp | 1 + source/net/protocol.h | 3 --- source/net/protocol_impl.h | 15 +++++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 source/net/protocol_impl.h diff --git a/source/net/communicator.cpp b/source/net/communicator.cpp index 3d6353a..22a7963 100644 --- a/source/net/communicator.cpp +++ b/source/net/communicator.cpp @@ -1,5 +1,6 @@ #include #include "communicator.h" +#include "protocol_impl.h" #include "streamsocket.h" using namespace std; diff --git a/source/net/protocol.cpp b/source/net/protocol.cpp index b24cef1..52678af 100644 --- a/source/net/protocol.cpp +++ b/source/net/protocol.cpp @@ -5,6 +5,7 @@ #include #include #include "protocol.h" +#include "protocol_impl.h" using namespace std; diff --git a/source/net/protocol.h b/source/net/protocol.h index 7ff63cb..05ea60e 100644 --- a/source/net/protocol.h +++ b/source/net/protocol.h @@ -455,9 +455,6 @@ const char *Protocol::Serializer::deserialize(P &pkt, const char *bu } -template -unsigned Protocol::PacketTypeDef

::class_id = 0; - template Protocol::PacketTypeDef

::PacketTypeDef(unsigned i): PacketDefBase(i), diff --git a/source/net/protocol_impl.h b/source/net/protocol_impl.h new file mode 100644 index 0000000..9ddf818 --- /dev/null +++ b/source/net/protocol_impl.h @@ -0,0 +1,15 @@ +#ifndef MSP_NET_PROTOCOL_IMPL_H_ +#define MSP_NET_PROTOCOL_IMPL_H_ + +#include "protocol.h" + +namespace Msp { +namespace Net { + +template +unsigned Protocol::PacketTypeDef

::class_id = 0; + +} // namespace Net +} // namespace Msp + +#endif -- 2.43.0