新人求解vc++书上二元重载
#include <iostream>using namespace std;
class IntArray
{
private:
int* pInt;
int nCount;
public:
IntArray(int count){
nCout=count
pInt=new int[nCount];
}
~IntArray(){
delete[]pInt;
pInt=NULL;
}
}
int operator[](int index) const{
if(index<0 || index>=nCout)
return 0;
return pInt[index];
}
void SetAt(int index,int value){
if(index<0 || index>=nCount)
return;
pInt[index]=value;
}
int GetLength(){
return nCount;
}
};
int main()
{
IntArray arr(3);
arr.SetAt(0,12);
arr.SetAt(1,45);
arr.SetAt(2,80);
for(int i=0;i<<arr.GetLength();i++0
{
cout<<"第"<<i+1<<"个元素"<<arr[i]<<endl;
}
cout<<endl;
return 0;
}
按书上打的二元重载 这能用于什么