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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:35:49+00:00 2026-05-19T12:35:49+00:00

I now I can do this in global scope and everything works fine: const

  • 0

I now I can do this in global scope and everything works fine:

const char* Foo::bars[3] = {"a", "b", "c"};

But I want to do this because this is much more clearer and self documenting (especially if you use Enums as the index):

const char* Foo::bars[3];
bars[0] = "a";
bars[1] = "b";
bars[2] = "c";

Is it anyway possible?

I know I can do this inside a function (for example, the class’s constructor) but what if the constructor is not called in the start of the program and I want to use the static array? That leads to problems.

  • 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-19T12:35:50+00:00Added an answer on May 19, 2026 at 12:35 pm

    In C++ there is no equivalent of the static Java block.

    If you really want to initialize the array automatically, you can create a simple class to do the job:

    // in .cpp
    class FooInitializer {
    public:
        FooInitializer() {
            Foo:bars[0] = "a";
            Foo:bars[1] = "b";
            Foo:bars[2] = "c";
        }
    };
    
    static FooInitializer fooInitializer;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now this must be easy, but how can sum two NSNumber ? Is like:
I know I can do this: IDateTimeFactory dtf = MockRepository.GenerateStub<IDateTimeFactory>(); dtf.Now = new DateTime();
Now that I can make useful user controls in WPF (thanks to this stackoverflow
Following on from this question I now have code that can attach to a
The best I can come up with for now is this monstrosity: >>> datetime.utcnow()
This problem crops up every now and then at work. Our build machine can
I understand that you can now create MVC-specific user controls, but will my existing
in the System.Linq namespace, we can now extend our IEnumerable's to have the Any()
How do you install Boost on MacOS? Right now I can't find bjam for
For some weeks now I simply can't run gem install in windows. It sticks

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.