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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:40:44+00:00 2026-05-30T10:40:44+00:00

I am using a scoped enum to enumerate states in some state machine that

  • 0

I am using a scoped enum to enumerate states in some state machine that I’m implementing. For example, let’s say something like:

enum class CatState
{
    sleeping,
    napping,
    resting
};

In my cpp file where I define a state transition table, I would like to use something equivalent to using namespace X so that I don’t need to prefix all my state names with CatState::. In other words, I’d like to use sleeping instead of CatState::sleeping. My transition table has quite a few columns, so avoiding the CatState:: prefix would keep things more compact and readable.

So, is there a way to avoid having to type CatState:: all the time?


Yeah, yeah, I’m already aware of the pitfalls of using namespace. If there’s an equivalent for strongly-typed enums, I promise to only use it inside a limited scope in my cpp implementation file, and not for evil.

  • 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-30T10:40:45+00:00Added an answer on May 30, 2026 at 10:40 am

    So, is there a way to avoid having to type CatState:: all the time?

    Not before C++20. Just as there’s no equivalent for having to type ClassName:: for static class members. You can’t say using typename ClassName and then get at the internals. The same goes for strongly typed enums.

    C++20 adds the using enum X syntax, which does what it looks like.

    You can of course not use enum class syntax, just using regular enums. But then you lose strong typing.

    It should be noted that one of the reasons for using ALL_CAPS for weakly typed enums was to avoid name conflicts. Once we have full scoping and strong typing, the name of an enum is uniquely identified and cannot conflict with other names. Being able to bring those names into namespace scope would reintroduce this problem. So you would likely want to use ALL_CAPS again to help disambiguate the names.

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

Sidebar

Related Questions

Why can't you access scoped variables using eval under a with statement? For example:
As usual, i've some trouble by using some ajax call on a requested scoped
In Windows environment, is Boost's scoped mutex using WinAPI's critical sections, or something else?
I understand if one were using a lot of widely scoped state, it's a
I have a model that looks something like this: class Comment < ActiveRecord::Base ...
I'm using the application-scoped settings to store settings that cannot change at run-time. I'm
Is it possible to have scoped macros using custom defined macros through boost wave?
I am using VSeWSS 1.3 to create a custom list definition scoped to 'Site'.
Sometimes, when using macros to generate code, it is necessary to create identifiers that
#include <iostream> using namespace std; class Sample{ public: enum{ x = 10 }; };

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.