【发布时间】:2017-12-01 23:41:08
【问题描述】:
我正在制作一个定义大小作为参数的简单地图,我希望将其存储在我的私有成员变量中。
我将展示一个简单的例子:
class A {
public:
A (const int size) {
map_size_ = size;
//or | both will not compile
int map[size][size];
}
private:
int map_size_;
int map_[map_size_][map_size_];
}
我知道 map_ 不会编译,但我想知道如何使用构造函数参数中的 const int 且不使用指针正确声明它。
【问题讨论】: