
Here is the compilable code: #include <boost/shared_array.hpp> #include <iostream> template <typename T> class VectorView; template <typename T> inline std::ostream& operator << (std::ostream& os, const VectorView<T>& VOut) { os<<VOut.size()<<std::endl; for (int i=0; i<VOut.size() && os.good(); ++i){ os<<VOut(i)<<""; os<<std::endl; } return os; } template<typename T> class VectorView { private: int _size; boost::shared_array<T> _vp; public: VectorView(T* ptr, int size) { _size=size; _vp=boost::shared_array<T>(ptr); } T operator () (int pos) const { return _vp[pos]; } int size() const { return _size; } ~VectorView() { } }; int main (void) { double a[]={1,2,3,4,5,6,7}; VectorView<double>V(a,4); std::cout<<V; return 0; } Any workaround?