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 7398187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:50:24+00:00 2026-05-29T03:50:24+00:00

When using strongly typed enums in a switch statement is there a way to

  • 0

When using strongly typed enums in a switch statement is there a way to avoid explicit casts to int?

/// @desc an enumeration of the states that the session can be in.
enum class State
{
    Created,    
    Connected,  
    Active,
    Closed
};

State sesState = session->GetState();

switch (static_cast<int>(sesState))
{
    case static_cast<int>(Session::State::Created):
    // do stuff.
    break;

    case static_cast<int>(Session::State::Connected):
    // do stuff.
    break;
}

From the n3242 draft:

6.4.2 The switch statement [stmt.switch]

2 The condition shall be of integral type, enumeration type, or of a class type for which a single non-explicit conversion function to integral or enumeration type exists (12.3).

Does enumeration type include strongly typed enums or are they incompatible with switch statements because they require an explicit conversion to int?

  • 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-29T03:50:24+00:00Added an answer on May 29, 2026 at 3:50 am

    An enumeration type is still an enumeration type even whether strongly typed or not, and have always worked fine in switch statements.

    See this program for example:

    #include <iostream>
    
    enum class E
    {
        A,
        B
    };
    
    int main()
    {
        E e = E::A;
    
        switch (e)
        {
        case E::A:
            std::cout << "A\n";
            break;
        case E::B:
            std::cout << "B\n";
            break;
        }
    }
    

    The output of this is “A”.

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

Sidebar

Related Questions

I noticed some odd behaviour when using the strongly typed HtmlHelper.ActionLink() extension method from
I'm using ADO.NET with a strongly typed dataset in C# (.NET 3.5). I want
I have developed a VB.NET program using a strongly typed dataset. This dataset has
Am using strongly typed view to show a complex object in a data entry/edit
I'm using a strongly typed DataSet for which manually adding rows will be error
I'm using the strongly typed Url.Action method from MvcContrib to do all of my
Background information first: We are using a strongly-typed DataSet to manage transaction files. That
I have a strongly-typed dataset (VB.NET), using .NET Framework 2.0. Given a DataRow in
Using EF4 Codefirst RC and MVC .NET I have a Strongly typed view I
When using Dapper-dot-net, if your querying to a strongly typed results, and your SQL

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.