title: Disable compiler warning 2100 for generic method in a list class that may contain pointers or not
body: <p>I am trying to make an ArrayList class in C++ as a learning experience. Similar to the Java ArrayList class it is a dynamic array, the internal array is called 'content'. Unlike in Java I wanted my ArrayList to be able to take pointers and non-pointers. But I am getting a problem, I am using std::is_pointer::value to check whether the generic type is a pointer within a number of functions. If it is a pointer the function will need to preform differently to if it was not a pointer. My example below shows my printAll() function which is meant to print every element in the array on separate lines. If the generic type is a pointer the method needs to dereference each element in the array before printing them.</p>
  
  <pre><code>   int main() {
          ArrayList&lt;int&gt; a = ArrayList&lt;int&gt;();
          a.add(1);
          a.add(2);
          a.add(3);
          a.printAll();
          cin.ignore();
      }
  
      #pragma warning(push)
      #pragma warning(disable : 2100)
      template&lt;class T&gt;
      void ArrayList&lt;T&gt;::printAll() {
          if (std::is_pointer&lt;T&gt;::value) {
              for (int i = 0; i &lt; this-&gt;occupiedSize; i++) {
                  cout &lt;&lt; "[" &lt;&lt; i &lt;&lt; "] " &lt;&lt; *this-&gt;content[i];
                  cout &lt;&lt; endl;
              }
          } else {
              for (int i = 0; i &lt; this-&gt;occupiedSize; i++) {
                  cout &lt;&lt; "[" &lt;&lt; i &lt;&lt; "] " &lt;&lt; this-&gt;content[i];
                  cout &lt;&lt; endl;
              }
          }
      }
      #pragma warning(pop)
  </code></pre>
  
  <p>On the line:
  <code>cout &lt;&lt; "[" &lt;&lt; i &lt;&lt; "] " &lt;&lt; *this-&gt;content[i];</code>
  I am getting warnings:
  C2100: illegal indirection and 
  C2088: '&lt;&lt;': illegal for class</p>
  
  <p>I'm assuming this is because the list is not of a pointer type and therefore cannot be dereferenced with *. But in a non-pointer list, std::is_pointer::value should return false and the code in that block is never executed anyway so it shouldn't be a problem. Disabling the warning doesn't seem to help.</p>
  
  <p>If I do:</p>
  
  <pre><code>int main() {
      ArrayList&lt;int*&gt; a = ArrayList&lt;int*&gt;();
      a.add(new int(1));
      a.add(new int(2));
      a.add(new int(3));
      a.printAll();
      cin.ignore();
  }
  </code></pre>
  
  <p>It works totally fine. Any ideas how I can solve this problem or how I can better implement this functionality?</p>
  
  <p>I am using windows 10, Microsoft Visual Studio (latest version I believe).</p>