title: How to return a template array in c++
body: <p>sortedArray – takes: an array, its size, boolean variable ascending, boolean variable inPlace.</p>
  
  <p>It will then return the sorted array. </p>
  
  <p>If ascending = false, the array will be sorted in descending order. </p>
  
  <p>If inPlace = false, the original array will not be changed.</p>
  
  <p>(To sort the array, I am using the function sort. And if needed, I am using the function reverseArray).</p>
  
  <p>n is the size of array arr[].</p>
  
  <pre><code>template&lt;class T&gt;
  T* sortedArray(T arr[], int n,bool asc,bool inplc) 
  { 
  if(inplc)
      {
      sort(arr,arr+n);
      return arr;
      }
  else if (inplc&amp;&amp;!asc)
      {
      sort(arr,arr+n);
      reverse(arr,arr+n);
      return arr;
      }
  else if (!inplc&amp;&amp;asc)
      {
      T* arr1=new T[n];
      for(int i=0; i&lt;n;i++)
          {
          arr1[i]=arr[i];
          }
      sort(arr1,arr1+n);
      return arr1;
      }
  else 
      {
      T* arr1=new T[n];
      for(int i=0; i&lt;n;i++)
          {
          arr1[i]=arr[i];
          }
      sort(arr1,arr1+n);
      reverse(arr1,arr1+n);
      return arr1;        
      }
  } 
  </code></pre>
  
  <p>The errors are fixed.</p>