Defining an element of the static structure of a C ++ class

I have not found a way to initialize a class member successfully inside the constructor, and I cannot understand why.

I have a header file:

#pragma once

struct STATE_MOUSE {
  bool moving;
  int left_button;
  int right_button;
  int middle_button;
  bool scroll_up;
  bool scroll_down;
};

class Message {
private:
  static STATE_MOUSE state_mouse;
public:
  Message();
  ~Message();
};

Then I have the source file:

#include "message.hpp"

STATE_MOUSE Message::state_mouse = {false, 0, 0, 0, false, false};

Message::Message() {
  //Would like to initialize state_mouse here somehow.
}

Message::~Message() {

}

Now about the problem. This seems to work. However, I use to initialize the members inside the constructor, and I have not found a way to do this with this static member of the structure.

The following method does not work, can someone explain why?

state_mouse.moving = false;
+4
source share
2 answers

static, class , class, . - -, static .

, static class, , class. , , , , .

+3

- . .

, cpp, undefined reference.

, - const int (, int, bool, char), - .

0

Source: https://habr.com/ru/post/1685203/


All Articles