(小参考):
template<typename T>
struct IVector2 {
T x, y;
IVector2(T x, T y) :
x(x), y(y) { }
};
有没有办法做到这一点:
static const IVector2<int> floors; // lowest / highest floor
std::vector<std::array<IPerson, floors.x - floors.y>> requestQueue;
我需要初始化数组大小以使floors.x和floors.y之间存在差异。我一直在寻找有关如何初始化楼层的答案,而我已经知道了]
const IVector2<int> IElevatorHandler::floors(-1, 4);
但是那不行。
(小参考):template
您可以尝试使用文字类。我对您的代码进行了一些更改
template<typename T>
struct IVector2 {
T x, y;
constexpr IVector2(T x, T y) : //constexpr constructor
x(x), y(y) { }
};
static constexpr IVector2<int> floors(10,1); // Initialized constexpr object. Now available at compile time