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

  • Home
  • SEARCH
  • 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 6767793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:59:37+00:00 2026-05-26T14:59:37+00:00

I am currently migrating my code from the old-style enum to enum class. The

  • 0

I am currently migrating my code from the old-style enum to enum class.

The strong-typing is nice, but I came across a point in the code where I needed to call ncurses’s init_pair() function which takes a short int as its first argument, but which I have converted to an enum class for developer-friendly reading.

To make the compiler happy, it seems that I need to use a static_cast<short int>() on the first parameter.

Is there a cleaner approach or if I must use the static_cast, how do you recommend that I use it?

Accepted Answer: Chris Dodd’s answer is good. Before the switch, I had ints all over the place representing the old-style enums. After the switch, I have one dirty cast with type-safe enums all over the rest of the code. The dirtiness is isolated to one spot, the code is safer, and it’s easier to read. This is a marked improvement.

  • 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-26T14:59:37+00:00Added an answer on May 26, 2026 at 2:59 pm

    The cleanest way is probably to define an overloaded inline version of init_pair that takes an enum and casts it to call the normal version:

    inline int init_pair(enum_type pair, short f, short b) {
        return init_pair(static_cast<short>(pair), f, b);
    }
    

    That way users can call it with you enum type and it will just work

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

Sidebar

Related Questions

I am currently migrating code from iBatis 2 to MyBatis 3. I have a
We're currently migrating from NMock2 to RhinoMocks and we're having trouble replicating this code:
I'm currently working on migrating an application from MS-Access to MS SQL Server. In
I am currently working on ClearCase and now migrating to GIT. But we need
We are currently migrating from PHP4 to PHP5 and have discovered an issue. In
We are currently migrating a WCF service from IIS 6 to IIS 7. The
Im currently looking at migrating from fluent nHibernate to ADO.Net Entity Framework 4. I
We are currently evaluating options for migrating from hand-written persistence layer to ORM. We
I'm investigating migrating a source code repository currently kept under SCCS on an aging
I'm currently migrating a working app from CakePHP 1.2 to 1.3. Most things seem

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.