0

I like to define my enum's that belong to a certain class inside that class. That makes it clear they belong together and helps against namespace pollution:

class Bar
{
public:

    enum class Foo
    {
        something,
        somethingElse
    };

    Bar(Foo foo);

    //etc...
};

Purely out of curiosity I'd like to know if one can do the same for a enum class that is used as template parameter for the class it's defined in:

template <Bar::Foo foo>
class Bar
{
public:

    enum class Foo
    {
        something,
        somethingElse
    };
};

Obviously this won't compile because Bar has not been declared yet at the moment we try to use Bar::Foo as a template parameter type. I'd like to see if someone can come up with some creative workaround.

Unimportant
  • 2,076
  • 14
  • 19
  • 1
    You cannot forward declare a nested type I fear. So no, not possible. – YSC Apr 26 '19 at 09:33
  • You could make the c'tor private and provide a public/friend factory function to only instance with specific template args. – George Apr 26 '19 at 09:36

0 Answers0