Here is a code listing from c++ primer plus. I don't understand how the copy constructor in this listing works
Code:#include <iostream> using namespace std; #include <cstdlib> template <class T, int n> class ArrayTP { private: T ar[n]; public: ArrayTP(); explicit ArrayTP(const T & v);// cpy constructor proto type virtual T & operator[](int i); virtual const T & operator[](int i) const; }; . . . . template <class T, int n> ArrayTP<T,n>::ArrayTP(const T & v) { for (int i=0; i<n; i++) ar[i]=v; //my question is here. i dont understand // shouldnt it be ar[i]=v[i]; } . . . .



LinkBack URL
About LinkBacks


