Question: How do i implement the class smartArray, as a class template elemtype to accept any numerical value. Below is code i have issues , in

How do i implement the class smartArray, as a class template elemtype to accept any numerical value.

Below is code i have issues , in being unable to make the ostream and istream work for the template

template class smartArray{ friend ostream& operator<<(ostream &,const elemType &); // i have issues with this friend istream& operator>>(istream &, elemType & ); // issues with making this work as template public: elemType *elements; // dynamic array, memory is allocated in the // constructor. Use *this to access size member. int length(); // returns the length of the array smartArray(); // default constructor, sets size to 0 smartArray(int size); // constructor, allocates the memory for *elements, if size==0, then no memory allocation is done ~smartArray() ;// destructor void resize(int newsize) ; private: int size; };

template ostream& operator<< (ostream &out,const elemType& b) { out << "[" ; for (int i = 0 ; i < b.size ;i++){ out << b.elements[i] << ","; } out << "]"; return out; }

template istream& operator>>(istream &in, elemType& b) { for (int i = 0 ; i < b.size ;i++) { cout << "Enter element number "<< i << ": "; in >> b.elements[i];} return in; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!