我编了一下,觉得还是有点问题
#include <iostream>
#include <string>
using namespace std;
class array
{
private:
int size;
//数组大小
int *element; //数组元素
public:
//array();
array(int);
int& elem (int); //返回第i+1个元素的引用
~array();
void print();
int Getint()
{
return size;
}
};
array::~array()
{
delete element;
}
array::array(int sz = 100)
{
size = sz;
element = new int [size];
}
int& array::elem(int i)
{
return element[i];
}
void array::print()
{
cout<<size<<endl;
}
int main(int argc,char* argv[])
{
int i;
array a(10);
for (i = 0;i<10;i++)
{
cin>>a.elem(i);
}
for (i = 0;i<10;i++)
{
cout<<"The element "<<i+1<<" is "<<a.elem(i)<<endl;
}
a.elem(2) = 23;
cout<<"The element is "<<a.elem(2)<<endl;
system("pause");
return 0;
}