Implementing std::auto_ptr::operator ->

I'm making my own auto_ptr-type class (I'd use the STL version, but I can't use it with containers), and I'm wondering, how does the auto_ptr class in <memory> implement its -> operator? When I use -> on an auto_ptr, Visual C++ brings up the menu as though it were implementing the dot operator on the object itself, and even though I've tried the same method (return &**_pointer) I can't get the same result, and any methods following the -> operator aren't being applied to the object being pointed to. Any idea how this is done?
you could just use shared_ptr. I don't think there's a standard lib version of it yet (unless you count tr1, but that isn't really standard). It's also part of boost. Might be worth looking into.

Anyway... -> operators typically look like this:

1
2
3
4
5
6
7
8
9
10
template <typename T>
class foo
{
private:
  T* ptr;

public:
  T* operator -> () { return ptr; }
  const T* operator -> () const { return ptr; }
};


As for getting the intellisense to match up with that -- afaik that's out of your control (unless you can mess with intellisense settings youself. But to my knowledge nothing can be done in your c++ code to make intellisense any smarter).
Last edited on
Topic archived. No new replies allowed.