0

I have a base class that has a template type. I am explicitly overriding this template type in the child class because that child class will only ever operate on the type that it is designed for. This is leading to linker errors however. I have two functions in the base class, one is provided since it will be common for all child classes. The other function is purely virtual and is to be meant to be overridden by the child class. I can compile and link the second function just fine, however linking the first function leads to an error:

 error LNK2019: unresolved external symbol "public: bool __thiscall BaseDecoder<class APacket>::unpack(class std::vector<unsigned char,class std::allocator<unsigned char> > const &,class std::vector<class Frame,class std::allocator<class Frame> > &)"  

This message sort of makes sense because there is no BaseDecoder<APacket> that implements the unpack function, just a BaseDecoder<class PacketType> implementation.

Here is my class structure:

Base class:

template <class PacketType>
class BaseDecoder {
public:
   BaseDecoder(){};
   virtual ~BaseDecoder(){};

    bool unpack(const std::vector<uint8_t>& traceData, std::vector<Frame>& frameData);
    virtual bool decode(std::vector<Frame>& frameData, std::vector<PacketType>& packetData) = 0;
}

Derived class:

class ADecoder : public BaseDecoder<APacket> {
public:
    ADecoder();
    ~ADecoder();

    bool decode(std::vector<Frame>& frameData, std::vector<APacket>& packetData) override;
}

Main:

std::vector<uint8_t>* raw_data = getRawData();
std::vector<Frame> frame_data;
a_decoder->BaseDecoder::unpack(*raw_data, frame_data);
std::vector<APacket> a_packets;
a_decoder->decode(frame_data, a_packets);

How can I get this to link the BaseDecoder<APacket> unpack() to BaseDecoder<class PacketType> unpack() instead, since that function does not actually touch the template type?

TheBat
  • 1,006
  • 7
  • 25

0 Answers0