title: About dynamic array construction in C++
body: <p>I'm revising my C++ skills for a machine learning project. So, I was working on a dynamically allocating memory functionality. My idea is define such functions as static ones and put them  a class and then call them as needed. So I defined following headerfile named Utils.h -</p>
  
  <pre><code>//Utils.h
  #include &lt;stdio.h&gt;
  
  class Utils
  {
  public:
      template&lt;class T&gt; static T* create1DArray(int size);            
  };
  </code></pre>
  
  <p>Then I created following Utils.cpp as - </p>
  
  <pre><code>//Utils.cpp
  #include&lt;stdio.h&gt;
  #include&lt;malloc.h&gt;
  #include"Utils.h"
  
  
  template&lt;class T&gt; T* Utils::create1DArray(int size)
  {
      T* a = new T [size];
      return a;
  }
  </code></pre>
  
  <p>Then I tested them as - </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;conio.h&gt;
  #include"Utils.cpp"
  
  using namespace std;
  int main()
  {
      cout&lt;&lt;"Test";
      double* a;    
      int n=3;
      a = Utils.create1DArray&lt;double&gt;(n);
      getch();
      return 0;   
  }
  </code></pre>
  
  <p>But I got following errors - </p>
  
  <pre><code>error C2275: 'Utils' : illegal use of this type as an expression    
  error C2228: left of '.create1DArray' must have class/struct/union  
  error C2062: type 'double' unexpected   
  </code></pre>
  
  <p>But surprisingly when I use this function as a standalone one without putting inside the function it works. Any idea how to solve it?</p>