vendredi 17 janvier 2020

Known array / pointer size as argument

InputManager* input = new InputManager(new int[]{ SDLK_UP, SDLK_DOWN, SDLK_LEFT, SDLK_RIGHT });

I wanna pass this array of keys (or a pointer to it) but i need the InputManager's constructor to know its size. Since its known at compile time how would i get it?

Online i found this template

template <int N>
InputManager::InputManager(int (&keyArray)[N]) {
    this->maxKeys = N;
    this->keys = keyArray;
}

But i get an error that the arguments dont match.

I need any possible solution where i dont need to manually write the length. So macros, templates or anything else is accepted.

Aucun commentaire:

Enregistrer un commentaire