/////////////////////////////////////////////////////////////////// // Vector.cpp - Solution of MT#3-Q1 // // // // This is a demo showing how to make the required declarations // // It provides no useful functionality. Main does nothing other // // Than create a Vector object. // /////////////////////////////////////////////////////////////////// template class Vector { public: Vector(int n); Vector(const Vector& v); ~Vector(); Vector& operator=(const Vector& v); // v1 = v2 Vector& operator*=(const T& t); // v1 *= t Vector operator*(const T&t); // v1 = v2*t Vector& operator+=(const Vector& v); // v1 += v2 Vector operator+(const Vector& v); // v1 = v2 + v3 Vector& operator-=(const Vector& v); // v1 -= v2 Vector operator-(const Vector& v); // v1 = v2 - v3 T& operator[](int n); // v1[3] = t T operator[](int n) const; // t = v1[2] private: int _numElem; T* array; }; //----< define global scalar mult ==> v1 = t*v2 >----------// template Vector operator*(const T&t, const Vector& v) { Vector temp; for(int i=0; i<_numElem; ++i) temp[i] = t*v[i]; return temp; } //----< define member functions >--------------------------// template Vector::Vector(int n) : array(new T[n]){} template Vector::~Vector() { delete [] array; } // define rest of the member functions here int main() { Vector v(10); // use Vector here }