title: Is it possible to declare a virtual static constant value in a C++ class?
body: <p>I'd like to have a base class that has a constant field (like an unique ID associated with the class that can't be modified after compile time). So far the <code>static const</code> declaration would be just fine. Now, I'd like to inherit this base class and make sure that the children of this class do have the same field, but with their own values. How can I do this?</p>
  
  <p>Let's say, I'd like to have a base class called <code>Base</code> with an <code>ID</code> field that holds the <code>int</code> value of 0. Then, I'd like to have the classes <code>A</code>, <code>B</code> and <code>C</code>, all of them being public children of <code>Base</code> and I'd like to make sure that these children would also have the <code>ID</code> fields with the respective values of 1, 2 and 3 (by 'making sure', I mean something like getting a compiler error if they don't have a ID explicitly declared).</p>
  
  <p>If I could manage to build this scenario, my expectation would be that asking for the <code>ID</code> field of a <code>Base*</code> pointer, I should get different values depending whether the pointer was created as <code>new A()</code>, <code>new B()</code> or <code>new C()</code>.</p>
  
  <p>My guess would be to declare <code>ID</code> as <code>virtual static const</code>, which of course doesn't make sense and gives a compiler error.</p>
  
  <p>But then what can I do to achieve the described result? (The only thing that I could imagine would be to declare <code>ID</code> as a virtual function returning an integer and then hard-code the value into the function body, but I'm looking for something more elegant.)</p>
  
  <p>Thank you in advance!</p>