title: Illegal use of this type as an expression when calling template class member
body: <p>I have a problem with the usage of a static class member <code>size</code> of a class <code>SizeObj</code>, which is used as template parameter for a template class <code>SizeTemplate</code>. See below the code snippet, which I reduced to the minimum. </p>
  
  <p>In fact that code below ran well up to MS VS2008, but now the compilation fails 
  when compiling with VS2010. The following error messages are displayed:</p>
  
  <pre><code>error C2275: 'K' : illegal use of this type as an expression
  error C2228: left of '.size' must have class/struct/union
  </code></pre>
  
  <p>It need to be said, that the compilation fails only, if the <code>getSize</code> method is
  called at least once.</p>
  
  <p>Please don't ask about the sense of the code below, as said I reduced it to the
  essential minimum to explain. However, I need to admit that the 
  usage of the member 'size' is not very elegant due to several reasons, and maybe
  there are lots of better solutions, but at the moment, I don't have any choice
  to keep it like that.</p>
  
  <p>Do you know what may be wrong here? Is it possible to solve that by build
  settings or something similar? I didn't find yet anything suitable yet.</p>
  
  <p>In the following posts it was easy, because an instance of class K is available, but for my problem, I don't know how to get that instance properly:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/42479842/illegal-use-of-type-in-template">Illegal use of type in template</a></li>
  <li><a href="https://stackoverflow.com/questions/24292895/simple-templated-function-to-convert-stdvectors-illegal-use-of-this-type-as">Simple templated function to convert std::vectors - &quot;illegal use of this type as an expression&quot;</a></li>
  </ul>
  
  <p><pre><code>
  //myTemplate.h</p>
  
  class SizeObj
  {
  public:
      static const int size = 1;
  };
  
  template&lt;class K&gt;
  class SizeTemplate
  {
  public:
      int getSize();
  };
  
  template&lt;class K&gt;
  int SizeTemplate&lt;K&gt;::getSize()
  {
      return K.size;
  }
  
  //main.cpp
  
  int main(...)
  {
      SizeTemplate&lt;SizeObj&gt; sizeObj;
      printf("size:%d", sizeObj.getSize());
  }
  </code></pre>
  
  <p>Thank you a lot in advance!</p>
  
  <p>tangoal</p>