In modern C++ you can define and initialise the member:
class Window
{
uint32_t mouseButtons_old = 0;
void Window::event(const vec2 &displaySize, SDL_Event &sdlEvent, bool wantCaptureMouse)
{
. . .
}
};
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, is there an alternative method instead of using static variable? And the code at bottom of this post explains how I want to use a simple method.
class MyClass {
public:
void func() {
static int value = 0; // Don't do it, example of how I may attempt to use it is with isUpdated.
printf("%d\n", value);
value++;
}
};
int main()
{
MyClass c1;
MyClass c2;
c1.func(); // Output: 0
c2.func(); // Output: 1 but it's not 0, so don't use a static variable inside a function in a class/struct.
_getch();
return 0;
}
In the example below, I attempted to use 'static' which seems to be a very simple method, but I shouldn't use it. Does anyone knows another simpler method?
This is my current solution but I don't believe it's the simplest: Make that variable a member variable of the class Window, but the problem is I must initialize it in the constructor to choose what initial value should it be, and it's too far from the main code, but if I always do that for my entire project then it seems weird, I don't know if there's another better method.
void Window::event(const vec2 &displaySize, SDL_Event &sdlEvent, bool wantCaptureMouse)
{
ModalEvent ev = {};
// Update window rect
setRect({ {0, 0}, displaySize });
_xx.drawData->_drawData->DisplayPos = { 0, 0 };
_xx.drawData->_drawData->DisplaySize = { displaySize.x, displaySize.y };
_xx.drawData->_drawData->FramebufferScale = { 1, 1 };
// mousePos, mouseButtons and make ImGui windows to be the mouse obstacles
static uint32_t mouseButtons_old = 0x0; // <---- This is an example of how I attempted to use 'static' inside the class Window, but there can be multiple windows.
uint32_t mouseButtons = 0x0;
...
}
In modern C++ you can define and initialise the member:
class Window
{
uint32_t mouseButtons_old = 0;
void Window::event(const vec2 &displaySize, SDL_Event &sdlEvent, bool wantCaptureMouse)
{
. . .
}
};
Viorel-1 > Thanks. I didn't know that method exists, I used it in a very far past but I forget. That's why forum is so helpful. I tried to Google the question before but there wasn't such answer. So thank you.