这是一个类,它基本上是一个我想要对其执行一些操作的数字数组。
class MyClass {
public:
MyClass() { //constructor
int * array = new int[n];
for(int i = 0; i < n; i++) {
array[i] = i*i;
}
} //end constructor
int displayIthElement(int i) {
return array[i];
}
}
我得到:错误,标识符“数组”在 displayIthElement 函数中未定义。就好像数组数组停止存在于构造函数之外,这是没有意义的。问题是什么?
非常感谢。