title: Getting the length of an array. Compiler errors.
body: <p>I've tried: </p>
  
  <pre><code>template &lt;typename T,unsigned S&gt; 
  unsigned getArraySize(const T (&amp;v)[S]) { return S; } 
  </code></pre>
  
  <p>after Motti's answer <a href="https://stackoverflow.com/a/18078435/512225">https://stackoverflow.com/a/18078435/512225</a> </p>
  
  <p>but I've got this message: </p>
  
  <p>error C2265: '' : reference to a zero-sized array is illegal </p>
  
  <p>What's wrong with my compiler? </p>
  
  <p>I gave a look at this page: 
  <a href="http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/4b78bcef-4c33-42f1-a4c5-fb6f702ced0b/vs6-c-compile-error-using-getaddrinfo" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/4b78bcef-4c33-42f1-a4c5-fb6f702ced0b/vs6-c-compile-error-using-getaddrinfo</a> 
  so I tried this solution: </p>
  
  <pre><code>template &lt;typename T,unsigned S&gt; 
  unsigned getArraySize(const T v[S]) { return S; } 
  </code></pre>
  
  <p>this compiles, but when I try to use it: </p>
  
  <pre><code>double myX[2] = {7,3};
  std::cout &lt;&lt; getArraySize(myX) &lt;&lt; std::endl; 
  </code></pre>
  
  <p>I get a compilation error:<br>
  error C2783: 'unsigned int __cdecl getArraySize(const T [])' : could not deduce template argument for 'S'</p>
  
  <p>Beside changing the compiler, is there a workaround I can use to get the array's size? </p>