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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:55:10+00:00 2026-05-12T17:55:10+00:00

So I just learned via a compiler error that in-class initialization of arrays is

  • 0

So I just learned via a compiler error that in-class initialization of arrays is invalid (why?). Now I would like to have some arrays initialized in a template class, and unfortunatly the contents depend on the template parameter. A condensed testcase looks like this:

template<typename T>
struct A {
    T x;
    static const int len = sizeof(T);         // this is of course fine
    static const int table[4] = { 0, len, 2*len, 3*len };    //this not
}

Any idea how to pull out the constant array?

EDIT: Added the ‘int’s.

  • 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-12T17:55:11+00:00Added an answer on May 12, 2026 at 5:55 pm

    Just as you’d do it without templates; put the initialization outside the class’ declaration:

    template<class T>
    const int A<T>::table[4] = { 0, len, 2*len, 3*len };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this is something that I should have learned by now, and
I just learned (the hard way) that Java Component s can only have one
I just learned about Java's Scanner class and now I'm wondering how it compares/competes
Just learned Python 3 in 7 days, and I have the feeling that there's
I just learned the hard way that IntPtr.Zero cannot be compared to default(IntPtr). Can
I just learned about ThreadLocal this morning. I read that it should always be
I just learned of vim's gf command for navigating to files that are referenced
So I just learned about preg_match in PHP the other day and now i'm
I have recently started with programming. So far I have learned basics and now
So I just now learned of the X-Robots-Tag which can be set as part

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.