title: What is the proper way to define a templated class's member function when behavior is identical for template types?
body: <p>Figuring if something wasn't broke, I'd break it, I decided to specialize a class I had so that it could be templated between float and double precision automagically.</p>
  
  <p>I have the following [simplified] class declaration:</p>
  
  <pre><code>// Quatcam.h
  #pragma once
  #include &lt;boost/math/quaternion.hpp&gt;
  #include &lt;boost/numeric/ublas/matrix.hpp&gt;
  template&lt;typename FloatType&gt;
  class QuaternionCamera
  {
  public:
      QuaternionCamera();
      void applyTranslation(boost::numeric::ublas::vector&lt;FloatType&gt; translationVector);
      boost::numeric::ublas::matrix&lt;FloatType&gt; getTranslationMatrix();
  
  protected:
      boost::numeric::ublas::vector&lt;FloatType&gt; m_location;
      boost::math::quaternion&lt;FloatType&gt; m_orientation;
  
  };
  </code></pre>
  
  <p>I have defined the member functions in a .cpp file:</p>
  
  <pre><code>//Quatcam.cpp
  #include "Quatcam.h"
  
  using namespace boost::numeric::ublas;
  
  template&lt;typename FloatType&gt;
  QuaternionCamera&lt;FloatType&gt;::QuaternionCamera()
      : m_location(3),
      m_orientation(1,0,0,0)
  {
      m_location[0] = m_location[1] = m_location[2] = 0;
  }
  
  template&lt;typename FloatType&gt;
  void QuaternionCamera&lt;FloatType&gt;::applyTranslation(boost::numeric::ublas::vector&lt;FloatType&gt; translationVector)
  {
      m_location += translationVector;
  
  }
  template&lt;typename FloatType&gt;
  boost::numeric::ublas::matrix&lt;FloatType&gt; QuaternionCamera&lt;FloatType&gt;::getTranslationMatrix()
  {
      boost::numeric::ublas::matrix&lt;FloatType&gt; returnMatrix = boost::numeric::ublas::identity_matrix&lt;FloatType&gt;(4,4);
  
      boost::numeric::ublas::vector&lt;FloatType&gt; invTrans = -m_location;
      returnMatrix(3,0) = invTrans[0];
      returnMatrix(3,1) = invTrans[1];
      returnMatrix(3,2) = invTrans[2];
      return returnMatrix;
  
  }
  </code></pre>
  
  <p>This code by itself will happily compile into a .lib or .obj file, but attempting to use the class in situ results in linker errors. Here is my example main.cpp attempting to use the class:</p>
  
  <pre><code>#include "Quatcam.h"
  #include &lt;boost/numeric/ublas/io.hpp&gt;
  #include &lt;iostream&gt;
  
  int main(int argc, char** argv)
  {
      QuaternionCamera&lt;float&gt; qcam;
  
      boost::numeric::ublas::vector&lt;float&gt; loc(3);
  
      loc[0] = 0;
      loc[1] = 5;
      loc[2] = 0;
      qcam.applyTranslation(loc);
  
      boost::numeric::ublas::matrix&lt;float&gt; qtm = qcam.getTranslationMatrix();
      std::cout &lt;&lt; "qtm: "&lt;&lt; qtm &lt;&lt; std::endl;
      return 0;
  
  }
  </code></pre>
  
  <p>This code fails to link with an error for missing symbols for getTranslationMatrix and applyTranslation. I assume this is because I haven't technically specified a full specialization of the functions for the type float. </p>
  
  <hr>
  
  <p><strong>Question(s)</strong></p>
  
  <p>Given that the behavior is the same for <em>any</em> atomic input type (float, double, even int, etc...) and only affects the precision of the answers.</p>
  
  <p>Is there a way to force the compiler to emit specializations for all of them without having to;</p>
  
  <ol>
  <li>move all of the function definitions into the header file, or; </li>
  <li>explicitly create specializations for all data types that would presumably involve a lot of copypasta?</li>
  </ol>