【发布时间】:2020-03-27 12:42:35
【问题描述】:
我有一个公共类,我在其中创建了一个数组,这个数组从构造函数中获取它的大小,并且需要在其他函数中使用(包括 int main)。因此变量必须是公开的。我的代码看起来是这样的:
class myclass {
public:
int parameter1;
int parameter2;
myclass(int p, int p2) {
parameter1 = p;
parameter2 = p2;
}
void makeArray() {
int array[parameter1][parameter2]; //I want this array to be public as the next method needs access to it
}
void otherFunction() {
array[1][2] = 5; //just an example of what i need to do
}
}
【问题讨论】:
标签: c++ arrays access-specifier