#include <iostream>
using namespace std;
class MyArray{
public:
MyArray(){
cout<<"默认构造的调用"<<endl;
this->pAddress=new int[this->m_Capacity];
this->m_Size=0;
this->m_Capacity=100;
}
MyArray(int Capacity){
cout<<"有参构造的调用"<<endl;
this->pAddress=new int[this->m_Capacity];
this->m_Size=0;
this->m_Capacity=Capacity;
}
MyArray(const MyArray& array){
cout<<"拷贝构造的调用"<<endl;
this->pAddress=new int[array.m_Capacity];
this->m_Size=array.m_Size;
this->m_Capacity=array.m_Capacity;
}
~MyArray(){
cout<<"析构的调用"<<endl;
if(this->pAddress!=NULL){
delete[] this->pAddress;
this->pAddress=NULL;
}
}
void push_Back(int val){
this->pAddress[this->m_Size]=val;
this->m_Size++;
}
int getData(int index){
return this->pAddress[index];
}
void setData(int val,int index){
this->pAddress[index]=val;
}
int getSize(){
return this->m_Size;
}
int getCapacity(){
return this->m_Capacity;
}
private:
int* pAddress;
int m_Size;
int m_Capacity;
};
void test01(){
MyArray* array1=new MyArray(30);
MyArray* array2=new MyArray(*array1);
MyArray* array3=array1;
MyArray array4=*array1;
for(int i=0;i<10;i++){
array1->push_Back(i);
}
for(int i=0;i<10;i++){
cout<<array1->getData(i)<<endl;
}
array1->setData(1000,0);
cout<<"现在array1[0]的值为:"<<array1->getData(0)<<endl;
cout<<"array1的数组大小为:"<<array1->getSize()<<endl;
cout<<"array1的数组容量为:"<<array1->getCapacity()<<endl;
}
int main() {
test01();
return 0;
}