H'H H'H - 10 days ago 5
C++ Question

boost::thread_specific_ptr cannot access private member declared in class

I am wondering if there is a way to resolve following issue without changing the ptr access type.

class A
{
private:
static boost::thread_specific_ptr< B> ptr;
public:
boost::thread_specific_ptr< B> get() { return poolmanager_boost; }
};


Error:

boost::thread_specific_ptr<B>::thread_specific_ptr': cannot access private member declared in class 'boost::thread_specific_ptr<B>'

Answer

The boost::thread_specific_ptr is non-copyable and therefore cannot be returned by value. Either return a (const) reference to the member ptr:

const boost::thread_specific_ptr< B> & get() const { return ptr; }

Or return the contained pointer:

B * get() const { return ptr.get(); }
Comments