title: Using class type in switch statement: is it better than using typeid operator?
body: <p>I saw below thing about switch statement in c++ standard $6.4.2.</p>
  
  <p>Switch statement can take a condition.</p>
  
  <blockquote>
    <p>The condition shall be of integral type, enumeration type, or of a class type for which a single conversion function to
    integral or enumeration type exists (12.3). If the condition is of class type, the condition is converted by calling that
    conversion function, and the result of the conversion is used in place of the original condition for the remainder of this
    section</p>
  </blockquote>
  
  <p>I tried below code which is working fine.</p>
  
  <pre><code>class Test
  {
  public:
      operator int() { return 1; }
  };
  
  int main()
  {
       Test obj;
       switch(obj)
       {
          case 1: cout&lt;&lt;"Test class object";
          break;
       }
  }
  </code></pre>
  
  <p>Is this a better way compared to using a typeid operator to find the object type ? </p>
  
  <p>In switch case way, the overhead is each class should have a unique integer id which will be returned by conversion function.</p>
  
  <p>In typeid way, if we use like typeid(obj) == typeid(Test), if else chain will be lengthy when we have many class types. Code readability decreases. May be its slower as well compared to switch case, as switch case may be implemented like a jump table by Compiler</p>
  
  <p>So, which way is better to find the object type at runtime ?</p>
  
  <p>EDIT: corrected question considering Andrey's comments.</p>