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

  • SEARCH
  • Home
  • 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 6683871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:52:22+00:00 2026-05-26T04:52:22+00:00

I have a templated struct with some enumerations in it and I’d like to

  • 0

I have a templated struct with some enumerations in it and I’d like to make a std::array with the enumerations in it for convenience. Is there any way of doing the following?

template< typename A >
struct someClass{
    enum class State{
        sA,
        sB,
        sC
    }

    static const std::array<State,4> the_states = {{
        State::sA,
        State::sB,
        State::sC
    }};

};
  • 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-26T04:52:23+00:00Added an answer on May 26, 2026 at 4:52 am

    No. Only static const integral data members can be initialized within a class.

    However, you could do this…

    template< typename A >
    struct someClass
    {
        enum State
        {
            sA,
            sB,
            sC
        };
    
        static const std::array<const State,4> the_states;
    };
    
    template<typename A>
    const std::array<const someClass::State,4> someClass<A>::the_states = 
    {
        someClass::State::sA, 
        someClass::State::sB, 
        someClass::State::sC 
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a struct that I'd like to output using either 'std::cout' or some
I have a dll that contains a templated class. Is there a way to
I have an std::vector -like class that is compiled with Visual C++ 2008. There's
I have a class like template <class T> struct A{ template <class U> A(U
I have code like this: template <typename T, typename U> struct MyStruct { T
In C++, can you have a templated operator on a class? Like so: class
I have developed a custom dijit Templated Widget. I have to do some DOM
Let's say I have some templated class depending on type T . T could
I have: struct DoubleVec { std::vector<double> data; }; DoubleVec operator+(const DoubleVec& lhs, const DoubleVec&
Say I have a templated Action template <class ArgT> struct Action { Action(::boost::function< void(ArgT)

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.