title: template <pointer> get type of object pointed to
body: <p>I'm trying to write a generic function to count bits in an array.  I'm trying to use <strong>template</strong> to define the functions.</p>
  
  <pre><code>template &lt;typename TYPE_T&gt;
  size_t countBits (TYPE_T testeeA, const size_t sizeA)
  {
      size_t count = 0;
  
      for (size_t item = 0; item &lt; sizeA; item++)
      {
          for (TYPE_T bit = 1; bit != 0; bit += bit)
          {
              if ((testeeA[item] &amp; bit) == bit) count++;
          }
      }
      return (count);
  }
  </code></pre>
  
  <p>But I need the second <strong>TYPE_T</strong> to be <code>char</code> when <strong>TYPE_T</strong> is <code>char*</code>.</p>
  
  <p>I tried <code>typename TYPE_T *</code> in the <strong>template</strong> argument but VS2012 C++ barfed.</p>
  
  <p>I can write this in preprocesser macro:</p>
  
  <pre><code>#define COUNTBITS(TYPE_T) \
  size_t countBits (TYPE_T * testeeA, const size_t sizeA) \
  { size_t count = 0; \
  for (size_t item = 0; item &lt; sizeA; item++) \
  { for (TYPE_T bit = 1; bit != 0; bit += bit) \
  . . .
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p>Thanks</p>