title: static_cast dynamic_cast: expected constant expression?
body: <p>In visual C++ 2010, when compiling the following codes, I get error message:</p>
  
  <p>static_cast error C2057: expected constant expression.</p>
  
  <p>what's wrong with that?</p>
  
  <pre><code>struct A {};
  struct B : A {};
  
  struct XX
  {
      static const int offset = (long)static_cast&lt;A*&gt;((B*)0x8) - 0x8;
  };
  </code></pre>
  
  <p>Thanks AProgrammer, the following is correct for VC 2010:</p>
  
  <pre><code>struct A {};
  struct B : A {};
  
  struct XX
  {
      static const int offset;
  };
  
  const int XX::offset
   = (long)static_cast&lt;A const*&gt;((B const*)0x8) - 0x8;
  </code></pre>