Question: I need help to 1. Add an overloaded operator!=() and operator==() functions. 2. Add the overloaded stream extraction and stream insertion operators To this class.
I need help to
1. Add an overloaded operator!=() and operator==() functions. 2. Add the overloaded stream extraction and stream insertion operators To this class.
So I just need help adding these operator overloads to this class I started on
myArray.h
#pragma once #ifndef H_myArray #define H_myArray #include
}; #endif H_myArray
myArray.cpp
#include "myArray.h" #include
myArray::myArray(int newSize)//Single parameter constructor { StartIndex = 0; size = newSize; //create pointer based array PtrAry = new int[size]; for (int i = 0; i < (size + StartIndex); i++) PtrAry[i] = 0; }
myArray::myArray(int newStartIndex, int newSize) //constructor two parameters { StartIndex = -newStartIndex; size = newSize; for (int i = 0; i < (size + StartIndex); i++) PtrAry[i] = 0;
}
myArray::~myArray() { delete[] PtrAry; }
int &myArray::operator[](int index)//implement overiding non constant array { if (index < -StartIndex || index >= size) { cerr << " Error:Index " << index << "is out of range" << endl; system("pause"); exit(1);//terminates }
return PtrAry[index + StartIndex]; }
int myArray::operator[](int index) const //const array overloader { if (index < -StartIndex || index >= size) { cerr << " Error:Index " << index << "is out of range" << endl; system("pause"); exit(1);//terminates } return PtrAry[index + StartIndex]; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
