i having a trouble to run this program because it come up C4716 error msg
please help with this thank you so much
#include<iostream>
using namespace std;
const int dSize = 10;
template<class T>
class SA{
private:
// pointer of type T
T* pT;
// low index
int lIdx;
// high index
int hIdx;
public:
SA()
{
// initiaize array of size 10
pT = new T[dSize];
lIdx = 0;
hIdx = 9;
}
// parametarized constructor
SA(int n)
{
// initiaize array of size n
pT = new T[n];
lIdx = 0;
hIdx = n - 1;
}
// parametarized constructor
SA(int l, int h)
{
// initiaize array of size n
pT = new T[h - l + 1];
lIdx = l;
hIdx = h;
}
// copy constructor
SA(const SA& arr)
{
int i;
// initilize array of appropriate size
this->pT = new int[arr.hIdx - arr.lIdx + 1];
this->lIdx = arr.lIdx;
this->hIdx = arr.hIdx;
// assign the array values of arr to the current object array
for (i = arr.lIdx; i <= arr.hIdx; i++)
this->pT = arr.pT[i];
}
// overloading operator =
void operator=(const SA& rhs)
{
int i;
// initilize array of appropriate size
this->pT = new int[rhs.hIdx - rhs.lIdx + 1];
this->lIdx = rhs.lIdx;
this->hIdx = rhs.hIdx;
// assign the array values of rhs to the current object array
for (i = rhs.lIdx; i <= rhs.hIdx; i++)
this->pT = rhs.pT[i];
}
~SA()
{
delete pT;
}
// overload [] operator
T& operator[](int offset)
{
// if index is valid
if (offset >= lIdx && offset <= hIdx)
return this->pT[offset];
else
{
cout << "Please enter valid index\n";
return this->pT[0];
}
}
// method to get size of array pT
int getSize()
{
// return the size of array
return hIdx - lIdx + 1;
}
friend ostream& operator<<(ostream &output, const SA &ob)
{
int i;
for (i = 0; i<10; i++)
output << ob.pT[i] << " ";
output << endl;
}
};
int main()
{
int i;
// object with values of type double
SA<int> intArr(5);
for (i = 0; i<5; i++)
// initialize array of intArr object
intArr[i] = i;
cout << "Array contents are ...\n";
// print content of intArr
cout << intArr;
// print size of array
cout << "\nSize = " << intArr.getSize() << endl << endl;
// object with values of type double
SA<double> dArr(10);
for (i = 0; i<10; i++)
// initialize array of dArr object
dArr[i] = i * 1.1;
cout << "Array contents are ...\n";
// print content of dArr
cout << dArr;
// print size of array
cout << "\nSize = " << dArr.getSize();
return 0;
}
friend ostream& operator<<(ostream &output, const SA &ob)
You need to return output.
delete pT;
should be delete [] pT;