Opened 11 years ago

Closed 9 years ago

#5686 closed Bugs (wontfix)

Member function and member variable pointers don't work well with shared_ptr

Reported by: patvarilly@… Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.45.0 Severity: Problem
Keywords: shared_ptr pointer-to-member Cc:

Description

The current implementation of shared_ptr doesn't overload operator->*, so member function and member variable pointers don't play nicely with shared_ptrs. I would imagine that this is trivial to fix given the existing operator-> implementation. Here's an example of what doesn't work but should:

class A
{
public: int memberA;
}

...
int A::*memberVariablePtr = &A::memberA;
shared_ptr<A> ASharedPtr( ... );

// The following two pieces of code should be functionally identical

// 1) Doesn't compile.  Error in g++: "base operand of -> is not a pointer"
//      It took me a while to figure out what g++ was complaining about
int val = ASharedPtr->*memberVariablePtr;   

// 2) Compiles and works just fine
int val = ASharedPtr.get()->*memberVariablePtr;

Note: I tried this with version 1.45.0, but looked up the documentation of shared_ptr in 1.46.1 to make sure that this hasn't already been addressed.

Change History (1)

comment:1 by Peter Dimov, 9 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.