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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:15:07+00:00 2026-06-09T23:15:07+00:00

I have a question related to C++ class member initialization. The following code illustrates

  • 0

I have a question related to C++ class member initialization. The following code illustrates my question:

class ABCD
{
public:
    ABCD():ObjNum(3){};
    ~ABCD() {};
     static const  unsigned char getByte[8];
     const int ObjNum;


};

const unsigned char ABCD::getByte[8] = {
    'a','b','c','d','e','f','g','h'
};

int main() 
{
     ABCD test;
     cout<<test.getByte[3]<<endl;


     return 0;
}

The above codes work very well, but now if I do not set getByte[8] as static, how could I initialize the class? I have tried in this way, but failed:

class ABCD
{
public:
    ABCD():ObjNum(3),getByte('a','b','c','d','e','f','g','h')
    {

    };
    ~ABCD() {};
    const  unsigned char getByte[8];
     const int ObjNum;


};



int main() 
{
     ABCD test;
     cout<<test.getByte[3]<<endl;


     return 0;
}

The error I have obtained is as follows:

 error C2536: 'ABCD::ABCD::getByte' : cannot specify explicit initializer for arrays

I understand the reason why I got the error, but I do not know how to fix it. Any idea? Thanks!

  • 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-09T23:15:09+00:00Added an answer on June 9, 2026 at 11:15 pm

    In C++11 you can initialize it like this:

    ABCD() : ObjNum(3), getByte{'a','b','c','d','e','f','g','h'} {}
    

    If you are going to use C++11, though, it would be better to use std::array as others have suggested in the comments. You could then define the array like:

    const std::array<unsigned char, 8> getByte;
    

    and initialize it in this way (note the double braces):

    ABCD() : ObjNum(3), getByte{{'a','b','c','d','e','f','g','h'}} {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following event class. I have a question related to the Property method
I have a question related to OOPS concept. I have a base class public
I have a Class named Question and a related Class named Answers. I want
This question is related to a WPF application. I have a class as below
I have a classes like this: public class member { public string name {get;set;}
I have a question related to Key Type initialization in HashMap. For example, I
I have a question related to the following link: What's the difference between Thread
This a question related to the initialization of objects in C++. I have a
I have a question related with VB.Net Code. I see that the DataTable we
This is a question related to RMI. i have 4 .class files an interface,it's

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.