Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:39:39+00:00 2026-05-26T10:39:39+00:00

I am working on a project where we had a standard enum like this:

  • 0

I am working on a project where we had a standard enum like this:

enum Services {
      RequestShower = 611,
      RequestBath = 617,
      RequestShave = 612,
      RequestHaircut = 618
};

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:

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

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

ostream operator<<(ostream& os, VatelPrivateService& service);

Well, I tried to implement like this:

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& operator<<(ostream& os, const VatelPrivateService& service)
{
   os << VatelPrivateService::getName(service);
   return os;
}

and call it like this:

cout << "item: " << VatelPrivateService::RequestShower << endl;

But the code above doesn’t compile – get :
error C2664: ‘VatelPrivateService::getName’ : cannot convert parameter 1 from ‘const VatelPrivateService’ to ‘int’

Hopefully you can see my intent. how do I fix this?

Angus

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:39:39+00:00Added an answer on May 26, 2026 at 10:39 am

    the latest C++ standard doesn’t regard an enum to be equivalent to an int

    The specification of enum has not changed: an enumerator is still implicitly convertible to its underlying integral type.

    C++11 adds a new concept, enum class, which is a “strongly typed and scoped enum.” This new kind of enumeration does not allow its enumerators to be implicitly converted to the underlying integral type (though, you can explicitly coerce the conversion using static_cast).

    If you want to write your own scoped enumeration that provides semantics and behavior similar to enum class but is usable on compilers that do not support enum class, you should read Howard Hinnant’s answer to this other question, wherein he provides a working example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am upgrading a project I had working previously. This code worked a few
I'm currently working on a project were I had to wrap the C++ classes
I am working on a project, and had all of my tests passing on
I was working on a project a few months ago, and had the need
I am working on a project where we'd like to pull content from one
I was working on project that had problem when encoding UFT-8 text into JSON
I have a web project that had UrlRewriter.NET installed and working fine on .NET
I had a working project, now I wanted to upgrade the layout and I'm
I am working on the project where i had used choice group in form.
I had a working project in VS2008 / .Net 3.5 using controls from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.