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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:53:56+00:00 2026-05-27T04:53:56+00:00

#include <iostream> struct a { enum LOCAL_A { A1, A2 }; }; enum class

  • 0
#include <iostream>

struct a {
  enum LOCAL_A { A1, A2 };
};
enum class b { B1, B2 };

int foo(int input) { return input; }

int main(void) {
  std::cout << foo(a::A1) << std::endl;
  std::cout << foo(static_cast<int>(b::B2)) << std::endl;
}

The a::LOCAL_A is what the strongly typed enum is trying to achieve, but there is a small difference : normal enums can be converted into integer type, while strongly typed enums can not do it without a cast.

So, is there a way to convert a strongly typed enum value into an integer type without a cast? If yes, how?

  • 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-27T04:53:57+00:00Added an answer on May 27, 2026 at 4:53 am

    Strongly typed enums aiming to solve multiple problems and not only scoping problem as you mentioned in your question:

    1. Provide type safety, thus eliminating implicit conversion to integer by integral promotion.
    2. Specify underlying types.
    3. Provide strong scoping.

    Thus, it is impossible to implicitly convert a strongly typed enum to integers, or even its underlying type – that’s the idea. So you have to use static_cast to make conversion explicit.

    If your only problem is scoping and you really want to have implicit promotion to integers, then you better off using not strongly typed enum with the scope of the structure it is declared in.

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

Sidebar

Related Questions

#include<iostream> template<class T> struct Foo { T v_; Foo(T&& v):v_(std::forward<T>(v)) { std::cout << building
#include <iostream> using namespace std; struct testarray{ int element; public: testarray(int a):element(a){} }; class
#include <iostream> typedef struct _person { std::string name; unsigned int age; }Person; int main()
#include <iostream> using namespace std; typedef struct { char streetName[5]; } RECORD; int main()
Consider this code: #include <iostream> template<class C> struct time { }; int main() {
MWE #include <iostream> struct Foo { Foo() { std::cout << Constructing Foo << this
#include <iostream> using namespace std; int main() { struct list { string name; int
#include<iostream> using namespace std; struct data { int x; data *ptr; }; int main()
Consider this: #include <iostream> struct A{ A(){ std::cout << Create empty A << std::endl;
#include stdafx.h #include <iostream> using std::cout; template<class T> class IsPolymorphic { template<class T> struct

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.