【发布时间】:2015-05-09 23:33:45
【问题描述】:
如何访问动态数组并为其设置值?例如数组[大小] = {8, 4, 3, 2, ...}
class Array
{
public:
Array(int sze)// default constructor
{
size = sze;
ptr = new int [size];
}
private:
int size; // number of elements in the Array
int *ptr = 0; // address of dynamically allocated memory
};
int main()
{
Array arry(10);
cout << arry.getSize();
//.....;
}
【问题讨论】:
-
您可以考虑使用 std::vector 或其他 stl 容器,而不是自己编写