Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copying the value of a const uint * to another variable in c++

I have a generic problem I suppose.

I`m currently learning C++ and SDL 2.0. SDL provides a function which returns a pointer to a const uint * containing all the keystates.

These are the variables I would like to use:

const Uint8* oldKeyState;
const Uint8* currentKeyState;

In the construction of my input.cpp:

currentKeyState = SDL_GetKeyboardState(&this->length);
    oldKeyState =  currentKeyState;

And in the Update() method I use:

oldKeyState = currentKeyState;
currentKeyState = SDL_GetKeyboardState(NULL);

However, instead of copying over the last values, all I do is giving a pointer to the oldKeyState, which in turn points to the current keystates..

So how do I go about copying the actual values from the variable's pointer to the current and old keystate? I don't want the pointer in my old keystate since I will not be able to check whether the previous state was UP and the new state is DOWN.

like image 209
Symphlion Avatar asked Feb 14 '23 12:02

Symphlion


1 Answers

Uint8 oldKeyState[SDL_NUM_SCANCODES];

// ...

memcpy(oldkeystate, currentKeyState, length);
like image 80
keltar Avatar answered May 08 '23 22:05

keltar