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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:24:35+00:00 2026-06-05T23:24:35+00:00

I would like to have a static char array member initialized in terms of

  • 0

I would like to have a static char array member initialized in terms of other static char array members – but the initialization is such that code is necessary. Is this possible?

class fred {
    static char *a;
    static char *b;
    static char c[4];
}

Now a and b will have fixed values, but I want to construct c in terms of them.
EG:

fred::a = "1234"
fred::b = "ab"    
strcpy(c, b);
strncat(c, a, 1);

However I can’t see anyway to initialize c, other than to make a class for the purpose which is just a char[4], with a constructor that references fred::a and fred::b, and then replace c in fred with an instance of that class – which is awkward when referencing the c char array.

Is there a better way?

  • 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-06-05T23:24:37+00:00Added an answer on June 5, 2026 at 11:24 pm

    Edit: Originally, I had wilma as a friend of fred, and a static instance of wilma doing the initialization. I have changed the example to have dino declared within fred since the OP said he thought that would be cleaner.

    You can create a static instance of a class inside fred whose job is to initialize c for you.

    class fred {
        static char *a;
        static char *b;
        static char c[4];
        static struct dino { dino (); } dino_flintstone;
    };
    
    char *fred::a;
    char *fred::b;
    char fred::c[4];
    fred::dino fred::dino_flintstone;
    
    fred::dino::dino () {
        fred::a = "1234";
        fred::b = "ab";
        strcpy(fred::c, fred::b);
        strncat(fred::c, fred::a, 1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a mapping function that does this: public static void
I have a static method in my code that I would like somehow to
I have several classes with static const data members. I would like to know
I have a structure that has an array of pointers. I would like to
I have an extension method that looks like the following: //[MethodImpl(MethodImplOptions.NoOptimization)] public static IEnumerable<char>
I would like to have our web applications pull static content (css, js, images)
So in my project i would like have a nice treeview that has images.
I would like to have an AppWidget that designed like this one . Image:
In C, I have an array of structs defined like: struct D { char
I would like to have a more colorful Python prompt in the terminal, just

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.