title: Explicit Template Specialization With Enumerated Types
body: <p>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.</p>
  
  <p>Unfortunately, since I'd like to make use of <code>std::bitset</code>, 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:</p>
  
  <p><em>My_Bytestream.hpp</em></p>
  
  <pre><code>#define NUMBITS(x) (x*sizeof(uint8_t))
  
  enum My_BytestreamType
  {
      BINARY = 1,
      ASCII = 2
  };
  
  template &lt;My_BytestreamType MULTIPLIER&gt;
  class My_Bytestream
  {
  public:
      My_Bytestream(My_Flag_t flags, My_Command_t command);
  
  private:
  
      boost::optional&lt;std::bitset&lt;NUMBITS(2 * MULTIPLIER) &gt;&gt; m_address;
      boost::optional&lt;std::bitset&lt;NUMBITS(2 * MULTIPLIER) &gt;&gt; m_CRC;
  };
  </code></pre>
  
  <p><em>MyBytestream.tpp</em></p>
  
  <pre><code>#include "stdafx.h"
  
  #include "My_Bytestream.hpp"
  
  template &lt;My_BytestreamType MULTIPLIER&gt; class My_Bytestream;
  
  template&lt;&gt;
  My_Bytestream&lt;My_BytestreamType::BINARY&gt;::My_Bytestream(My_Flag_t flags, My_Command_t command)
  {
      m_command = command;
  }
  </code></pre>
  
  <p>However, this results in the following <strong>linker</strong> error:</p>
  
  <pre><code>error LNK2019: unresolved external symbol "public: __thiscall My_Bytestream&lt;1&gt;::My_Bytestream&lt;1&gt;(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)
  </code></pre>
  
  <p>Note that <code>My_Flag_t</code> and <code>My_Command_t</code>are defined as (unrelated) enumerations in another header.</p>