Ask coding questions

← Back to all posts
[ C++ ] [ enums ] Coder100 got lazy
h
Coder100 (16904)

using namespace enum

obviously you can't do this, but in C++, we haz

namespace pseudoenum { int FIRST = 1, SECOND = 2, THIRD = 10; }

using namespace pseudoenum;
// FIRST, SECOND, THIRD

which captures what I want to do with a real enum perfectly.

pings: @DynamicSquid @fuzzyastrocat
is this a discord question?

thanks no alt this time bye

Edit

apparantly I am bad questioneer so,

enum pog { a, b, c };

does what I want (all the 'enumerations' are into global scope), is there a way to do that for enum class?

Comments
hotnewtop
sugarfi (626)

just nest an enum in a namespace...

namespace x {
  typedef enum {
    A, B, C
  } y;
}
// x::A, x::B, etc.
DynamicSquid (4628)

What's your question?

RayhanADev (1966)

@DynamicSquid when Coder100 posts a question in Ask

What’s your question?

Coder100 (16904)

ok so the question is how do i extract all the 'enumerations' into the
global scope, sort of like how enum whatever {} does the trick @DynamicSquid

RYANTADIPARTHI (5999)

What is your question? Can you be specific.

RYANTADIPARTHI (5999)

@Coder100 if you are asking about getting same scopes in a enum class, then yes you can do it.

RYANTADIPARTHI (5999)

@Coder100 Try this:

enum Fruit
    {
        fruit_apple, // same scope
        fruit_pineapple
    };
Coder100 (16904)

@RYANTADIPARTHI im not here for scoped enums i said class enums

RYANTADIPARTHI (5999)

@Coder100 i think you can:

enum TradeSignal { Buy, Sell }; 
DynamicSquid (4628)

Do you mean scoped enums?

enum class SomeEnum
{
  FIRST,
  SECOND,
  THRID
};

SomeEnum obj = SomeEnum::FIRST;