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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:29:11+00:00 2026-06-10T22:29:11+00:00

enum bool { FALSE = 0, TRUE = 1 }; I’m wondering how to

  • 0
enum bool
{
    FALSE = 0,
    TRUE = 1
};

I’m wondering how to translate this in a modern C++ approach and if there is a well suited container for that; i know that the enum are not really that appreciated, but i can’t think about a real alternative in the C++ world.

What if would like to associate the execution of a particular method with a state?


Ok, this is the part where i will be more verbose.

I would like to stress the fact that i’m asking about structures symbolic constants and not about TRUE and FALSE, i’m not that “needy”.

Suppose that i have a structure that can represent several states with their own constants

enum semaphore
{
    GREEN = 0,
    ORANGE = 1,
    RED = 2
};

this is C code, now my question is about how to do the same in C++ if there is a better way.

My question continue when i ask about the possibility to do something like an automatic triggering when a change of state will occur, for example:

int main
{
   ...
   semaphore = 1;
   ...
}

and without any extra statements this has to trigger a method() just because the semaphore is now orange.

I hope that is more clear now.

  • 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-06-10T22:29:12+00:00Added an answer on June 10, 2026 at 10:29 pm

    What if would like to associate the execution of a particular method with a state?

    I’m not sure I get your point, but maybe you mean something like this:

    DEFINITION

    Instead of this:

    enum BOOL
    {
      FALSE = 0,
      TRUE = 1
    };
    
    void executeOnlyWithTrue(BOOL b)
    {
      if (b == TRUE)
      {
        RunParticularMethodOnlyNeededForTrueState();
      }
    }
    

    You do this:

    class BOOL
    {
    public:
      virtual void  executeOnlyWithTrue() const {/*default does nothing*/} 
    };
    
    class FALSE : public BOOL
    {  //no override, so using default executeOnlyWithTrue (BOOL's) 
    };
    
    class TRUE : public BOOL
    {
    public:
      virtual void  executeOnlyWithTrue() const
      {
        RunParticularMethodOnlyNeededForTrueState();
      }
    };
    

    USAGE

    Instead of this:

    const BOOL b = TRUE;
    ...
    executeOnlyWithTrue(b)
    ...
    

    You do this:

    const BOOL& b = TRUE();
    b.executeOnlyWithTrue();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any downside to using typedef char bool; enum boolean { false, true
#include <stdio.h> enum bool { true, false }; typedef bool (*compare_fun) (int, int); I
I am writing a function as follows: bool abc::GetLoggingStatus() { //true or false is
Why does this return False public enum Directions { Up, Down, Left, Right }
With enum under .net the biggest number you can use is ULong. This mean
If I declared a bool isTrue = false; // init it to false and
There is a class definition and some bool functions which test some attributes class
there any way to define enum in c# like below? public enum MyEnum :
class Board { public: enum Player {X = -1, O, E}; bool win(Player P);
Why compiler cannot specialize this function and is there a way to force him

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.