Why doesn't auto_ptr support op->*()

Viewed 334

auto_ptr (shared_ptr as well) try to make their use as transparent as possible; that is, ideally, you should not be able to tell a difference whether you're using an auto_ptr or a real pointer to an object. Consider:

class MyClass
{
public:
    void foo() {  }
};

MyClass* p = new MyClass;
auto_ptr<MyClass> ap(new MyClassp);

p->foo();       // No notational difference in using real
ap->foo();      // pointers and auto_ptrs

When you try to invoke a member function through a pointer-to-member, there is a difference, as auto_ptr obviously doesn't implement op->*():

void (MyClass::*memfun)() = &MyClass::foo;

(p->*memfun)();         // OK
(ap->*memfun)();        // Error op->*() missing
(ap.get()->*memfun)();  // OK

Why is there no support for op->*() in auto_ptr and how would one implement it (I've experimented for some time, but ultimately gave up).

3 Answers
Related