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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:29:42+00:00 2026-06-05T20:29:42+00:00

Initializing in the header file i get the following error: invalid in-class initialization of

  • 0

Initializing in the header file i get the following error:

invalid in-class initialization of static data member of non-integral type 'bool [8]'

if i try to initialize in the .cpp, i get:

'bool Ion::KeyboardInput::key [8]' is a static data member; it can only be initialized at its definition

Heres the header:

enum MYKEYS {
    KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_W, KEY_S, KEY_A, KEY_D
};

class KeyboardInput
{
public:
    KeyboardInput();
    ~KeyboardInput();
    static void getKeysDown(ALLEGRO_EVENT ev);
    static void getKeysUp(ALLEGRO_EVENT ev);
    static bool getKey(int keyChoice);

private:
    static bool key[8] = {false, false, false, false, false, false, false, false};
};
  • 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-05T20:29:43+00:00Added an answer on June 5, 2026 at 8:29 pm

    The first error message informs you that it is improper to initialize the static member variable in the header file. The second error message implies you tried to initialize the static member key in your constructor.

    A static class member variable needs to be declared inside the class (without initialization) and then defined outside of the class in the .cpp file (sort of like a global variable, except the variable name has the class name included with it).

    bool KeyboardInput::key[8];
    

    The definition of the variable may include an initializer. Since you were initializing it to all false, the above definition in your .cpp file is sufficient.

    A static class member variable is not too different from a global variable, except that it is scoped by the class name, and can be protected to only be accessible by members of the class (with private), the class’s immediate subclasses (with protected), or the class’s friends.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have the following in a header file: Foo.h Foo { public: static
I have a header file: class day { public: day(int id); ~day(); private: int
I have the following deceleration in my header file // 3D Vector typedef struct
I'm initializing jplayer with the following parameters: $jplayer.jPlayer('setMedia',{ mp3: data.audioMP3, oga: data.audioOGA }); Assume
I'm initializing in a class a pointer to be NULL. Afterwards I check if
The glassfish error INFO: Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/NNTPjsf' INFO: WEB0671:
Is it OK to reference this when initializing a field? public class MainClass {
I have in my header Test.h a variable of a class that doesn't have
The header file contains two variables. Because of the structure of my program, I
Okay, I am having trouble with the following piece of code (in a header

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.