title: How to overload + operator for arrays in C++?
body: <p>For a C++ exercise for school I need to overload the + operator to concatenate 2 arrays. And I need to do that in a generic class.</p>
  <p>for ex:</p>
  <pre><code>a1 = {1, 3, 4}
  a2 = {2, 3, 5, 6}
  =&gt; a = {1, 3, 4, 2, 3, 5, 6}
  </code></pre>
  <p>And I have this code but it's not working.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;array&gt;
  
  using namespace std;
  
  template &lt;class T&gt;
  T operator+(const T&amp; a1, const T&amp; a2)
  {
    T a;
    for (typename T::size_type i = 0; i &lt; a1.size() + a2.size; i++) {
        if (i &lt; a1.size()) {
          a[i] = a1[i];
        } else {
            a[i] = a2[i];
        }
    }
    return a;
  }
  
  int main()
  {
    array&lt;int,3&gt; a1 = { 1, 3, 4 };
    array&lt;int,4&gt; a2 = { 2, 3, 5, 6 };
    array&lt;int,7&gt; a3 = a1 + a2;
  
    for (int i = 0; i &lt; 5; i++)
      cout &lt;&lt; a1[i] &lt;&lt; '+' &lt;&lt; a2[i] &lt;&lt; '=' &lt;&lt; a3[i] &lt;&lt; ' ';
  
    cout &lt;&lt; endl;
    return 0;
  }
  </code></pre>
  <p>This code doesn't work, this is what I receive in the console:</p>
  <pre><code>main.cpp:32:24: error: no match for ‘operator+’ (operand types are ‘std::array’ and ‘std::array’)
     array&lt;int,7&gt; a3 = a1 + a2;
                       ~~~^~~~
  main.cpp:15:3: note: candidate: template T operator+(const T&amp;, const T&amp;)
   T operator+(const T&amp; a1, const T&amp; a2)
  </code></pre>
  <p>What should I do to resolve the problem? And another question, does this code use generic class? Any feedback will be appreciated!</p>