title: C++ class template for similar classes
body: <p>I have a socket data type class that is used to read and parse a value from socket stream (may be used for file too).<br>
  Let my class be <code>mc_double</code>:</p>
  
  <pre><code>class mc_double {
      private:
             double value;
      public:
             bool read(socket);
             write(double);
  }
  </code></pre>
  
  <p>Actual class is more complicated, but this is the principle. Now, I need to parse <code>float</code> from the stream. Float is way similar to double, so is already implemented <code>int</code>. Could't I merge this class definitions, with all <code>double</code>, <code>int</code> and <code>float</code> somehow templated?</p>
  
  <p>This is what I mean:</p>
  
  <pre><code> class mc_&lt;typename = double or int or float&gt; {
      private:
             typename value;
      public:
             bool read(socket);
             write(typename);
  }     
  </code></pre>
  
  <p>Some methods would be then defined individualy as <code>mc_double::method()</code> others would be same for all types: <code>mc_typename::general_method()</code>. Also, for some I'd need just minor changes in code:</p>
  
  <pre><code>typename mc_typename::return_value() {
           return val;
  }
  </code></pre>
  
  <p>Or the constructor:</p>
  
  <pre><code>mc_typename::mc_typename(&lt;int, long, char, double&gt; number) {
          val = (typename)number;
  }
  </code></pre>
  
  <p>The result should be <strong>three</strong> classes - <code>mc_int</code>, <code>mc_float</code> and <code>mc_double</code>.<br>
  I have found the official C++ template docs, but I only figured out the last part of my question - I can create a function that accepts multiple data types. The rest does not seem to be that easy.</p>