Replacing enum with class with int identifiers - doesn't compile
<p>I am working on a project where we had a standard enum like this:</p>

<pre><code>enum Services {
      RequestShower = 611,
      RequestBath = 617,
      RequestShave = 612,
      RequestHaircut = 618
};
</code></pre>

<p>But my boss was saying that the latest C++ standard doesn't regard an enum to be equivalent to an int so instead proposed using a class a bit like this:</p>

<pre><code>class VatelPrivateService {
public:
   static const short
      RequestShower = 611,
      RequestBath = 617,
      RequestShave = 612,
      RequestHaircut = 618;

   static const char* getName(int val);
};

ostream operator&lt;&lt;(ostream&amp; os, VatelPrivateService&amp; service);
</code></pre>

<p>Well, I tried to implement like this:</p>

<pre><code>const char* VatelPrivateService::getName(int id)
{
 #define CASE_NM(rq) case rq: return #rq
   switch(id)
   {
      CASE_NM(RequestShower);
      CASE_NM(RequestBath);
      CASE_NM(RequestShave);
      CASE_NM(RequestHaircut);
   }
#undef CASE_NM
   return "";
}

ostream&amp; operator&lt;&lt;(ostream&amp; os, const VatelPrivateService&amp; service)
{
   os &lt;&lt; VatelPrivateService::getName(service);
   return os;
}
</code></pre>

<p>and call it like this:</p>

<pre><code>cout &lt;&lt; "item: " &lt;&lt; VatelPrivateService::RequestShower &lt;&lt; endl;
</code></pre>

<p>But the code above doesn't compile - get :
error C2664: 'VatelPrivateService::getName' : cannot convert parameter 1 from 'const VatelPrivateService' to 'int'</p>

<p>Hopefully you can see my intent.  how do I fix this?</p>

<p>Angus</p>
