Classes in the array
{
Public:
int array(int size); //size is the array size, and all elements are initialized to 0.
~ int array();
int size()const; //Get the array size
int & ampitem(int I); //Ask to judge whether I have crossed the line. If you cross the line, it will be terminated.
Invalid allocation (array & AMPA); //Copy all elements of array A to the corresponding positions of the array. It is necessary to determine whether the size of a exceeds this array, and if it exceeds this array, it will be terminated.
Void display (); //Output all elements of the array
Private:
int m _ iSize
int * m _ pData
};
IntArray::IntArray(int size)
{
m _ iSize = size
m _ pData = new int[size];
memset(m_pData,0,sizeof(int)* size);
}
IntArray::~IntArray()
{
Delete m _ pData
}
int IntArray::size() const
{
Returns m _ iSize
}
int & ampIntArray::item(int i)
{
If (i>= m_iSize)
Returns m _ pdata [0];
return m _ pData[I];
}
void IntArray::assign(IntArray & amp; answer
{
if(a . size()& gt; size())
Return;
m _ iSize = a . size();
for(int I = 0; I<m _ iSizei++)
m _ pData[I]= a . m _ pData[I];
}
void in array::display()
{
for(int I = 0; I<m _ iSizei++)
printf("%d ",m _ pData[I]);
printf(" \ n ");
}
void main()
{
IntArray intArr(5);
intarr . display();
for(int I = 0; I & ltintarr.size (); i++)
intarr . item(I)= I * 2+5;
intarr . display();
}
This is almost a reference! parents