Original Post
I was going through a smart pointer tutorial and I have a few questions about this format: template <class T> class auto_ptr { T* ptr; public: explicit auto_ptr(T* p = 0) : ptr(p) {} ~auto_ptr() {delete ptr;} T& operator*() {return *ptr;} T* operator->() {return ptr;} // ... }; First of all what does the line: T& operator*() {return *ptr;} Mean? It looks like it is just returning the contents of ptr, but what is the & operator for? Also on the line below it, I’d assume that it is just return the ptr pointer. It that is the case, then would I have to do the following to call a function: auto_ptr x; … … x->->DoSomething(); Also how do I control whether the operator is going to before or after the variable. For example, how would I do an overload for this: Some_ptr = &x