我设置了一个类:
class Example {
static const float array[3][8];
};
并实施
inline const float below_center(const float pos) {
return pos - (size / 2); // size is a const float
}
inline const float above_center(const float pos) {
return pos + (size / 2);
}
inline const float *set_pos(const float x, const float y) {
return (float []) {
below_center(x), below_center(y),
below_center(x), above_center(y),
above_center(x), below_center(y),
above_center(x), above_center(y),
};
}
const float Example::array[3][8] = {
set_pos(2.0f, 0.0f),
set_pos(-1.0f, -1.0f),
set_pos(1.0f, -1.0f),
};
但是当我这样做时,我收到一条错误消息,“在初始化中将'const float*' 转换为'const float'”。我明白错误在说什么,但到底是在说“const float”,以及如何用分解的内联函数来实现我的数组。