title: How to check if a data type is an array? (C++)
body: <p>So I am currently a student and have run into the following exercise:
  Write a function that prints the elements in an array. The array is sent to the function by argument. If this argument is not an array, an exception of type invalid_argument must be thrown. Test the function in the main() function.</p>
  
  <p>So my code is currently as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;exception&gt;
  #include &lt;string&gt;
  
  using std::cin;
  using std::cout;
  using std::endl;
  using std::invalid_argument;
  using std::string;
  
  template&lt;class T&gt;void printArray(T arr){
      try{
          arr.size();
      }
      catch(...){
          for (int i=0; i &lt; sizeof(arr); i++){
              cout &lt;&lt; arr[i] &lt;&lt; endl;
          }
      }
      throw invalid_argument("Argument not of type array");
  };
  
  int main(){
      string arrChars[5] = {"1", "2", "3", "John", "5"};
      string s = "Jack";
      try{
          printArray(arrChars);
      }
      catch(invalid_argument &amp;e){
          cout &lt;&lt; "Error: " &lt;&lt; e.what() &lt;&lt; endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>This is after already trying other options such as:</p>
  
  <pre><code>template&lt;class T&gt;void printArray(T arr[]){
  ...
  }
  </code></pre>
  
  <p>Which doesn't allow the program to run either as I cannot pass any arguments to the <code>printArray()</code> function that are not arrays.</p>
  
  <p>My plan with the code is to swap out <code>arrChars</code> and <code>s</code> as the arguments to <code>printArray()</code> in order to determine success off the program.</p>