【发布时间】:2020-01-17 16:21:09
【问题描述】:
InputManager* input = new InputManager(new int[]{ SDLK_UP, SDLK_DOWN, SDLK_LEFT, SDLK_RIGHT });
我想传递这个键数组(或指向它的指针),但我需要 InputManager 的构造函数来知道它的大小。既然它在编译时就知道了,我怎么得到它?
我在网上找到了这个模板
template <int N>
InputManager::InputManager(int (&keyArray)[N]) {
this->maxKeys = N;
this->keys = keyArray;
}
但我得到一个参数不匹配的错误。
我需要任何可能的解决方案,我不需要手动编写长度。所以宏、模板或其他任何东西都可以接受。
【问题讨论】:
标签: c++ c++11 templates macros