0

I have a class whose implementation differs (slightly) depending on a said multiplier. Basically, it will ultimately be a serial data packet. When placed in ASCII mode, the width of a number of bit-fields will double and those fields will differ in format.

Unfortunately, since I'd like to make use of std::bitset, I cannot declare the widths dynamically. The most reasonable approach I could muster up was to use templates instead. I'd like to separate the template definition from the implementation. As such, I've done the following:

My_Bytestream.hpp

#define NUMBITS(x) (x*sizeof(uint8_t))

enum My_BytestreamType
{
    BINARY = 1,
    ASCII = 2
};

template <My_BytestreamType MULTIPLIER>
class My_Bytestream
{
public:
    My_Bytestream(My_Flag_t flags, My_Command_t command);

private:

    boost::optional<std::bitset<NUMBITS(2 * MULTIPLIER) >> m_address;
    boost::optional<std::bitset<NUMBITS(2 * MULTIPLIER) >> m_CRC;
};

MyBytestream.tpp

#include "stdafx.h"

#include "My_Bytestream.hpp"

template <My_BytestreamType MULTIPLIER> class My_Bytestream;

template<>
My_Bytestream<My_BytestreamType::BINARY>::My_Bytestream(My_Flag_t flags, My_Command_t command)
{
    m_command = command;
}

However, this results in the following linker error:

error LNK2019: unresolved external symbol "public: __thiscall My_Bytestream<1>::My_Bytestream<1>(enum My_Flag_t,enum My_Command_t)" (??0?$My_Bytestream@$00@@QAE@W4My_Flag_t@@W4My_Command_t@@@Z) referenced in function "public: __thiscall My_Binary_Command::My_Binary_Command(enum My_Flag_t,enum My_Command_t)" (??0My_Binary_Command@@QAE@W4My_Flag_t@@W4My_Command_t@@@Z)

Note that My_Flag_t and My_Command_tare defined as (unrelated) enumerations in another header.

audiFanatic
  • 2,296
  • 8
  • 40
  • 56

0 Answers0