0

This is class of array to access the array of IntegerSet. You need access to the pointer ptr of IntegerSet GetPtr();

You need access to the capacity of IntegerSet GetCapacity();

GetPtr() const to const IntegerSet class.

class IntegerSet
{
 private:
    int capacity;
    int nelements;
    int * ptr;
public :
IntegerSet(int  size);
~IntegerSet();
int * GetPtr() const {return ptr;};
int Getcapacity() const {return capacity;};
IntegerSet &  operator =(const IntegerSet & rhs1);
friend IntegerSet  operator +(const IntegerSet & rhs1,const IntegerSet & rhs2);
};

IntegerSet::IntegerSet(int  size)
{
ptr=null;
capacity = size;
ptr = new int [capacity];
if(ptr==null) cout << "error allocation"<< endl;

}
~IntegerSet()
{
if (ptr) delete ptr;
}
IntegerSet & IntegerSet::operator =(const IntegerSet & rhs1)
{
int capacity_=rhs1.Getcapacity();
int *rptr1=rhs1.GetPtr();
for (int i=0;i<capacity_;i++)
{
ptr[i]=rptr1[i]; // ptr is pointer of class IntegerSet 
}
return *this;
}
 //this function friend of class IntegerSet is extern ..
IntegerSet  operator +(const IntegerSet & rhs1,const int& rhs2)
{
int capacity_=rhs1.Getcapacity();
IntegerSet  temp(capacity_);
int *rptr1=rhs1.GetPtr();
int *tptr=temp.GetPtr();
for (int i=0;i<capacity_;i++)
{
tptr[i]=rptr1[i]+rhs2;
}
return temp;
}

what's difference between two function int * GetPtr() const and int * GetPtr(); ?

0 Answers0