Boost logo

Boost Users :

Subject: [Boost-users] privately inherit enable_shared_from_this?
From: Eric J. Holtman (eric_at_[hidden])
Date: 2009-12-11 12:52:13


I have some code that uses enable_shared_from_this.

I was publicly deriving, i.e. (and this works)

class Request : public boost::enable_shared_from_this<Request> {
};

I wanted to change my code around so that I wrapped
the shared_from_this function inside the class, so that
I could check at runtime whether certain conditions hold,
i.e.

class Request : private boost::enable_shared_from_this<Request> {
public:
    boost::shared_ptr<Request> get_ptr () {
        if (conditions_are_good)
             return shared_from this ();
        else
             throw std::logic_error ("Bad get");
    };
};

This won't compile (visual studio 2008).

1>Compiling...
1>Request.cpp
1>c:\boost\boost_1_40_0\boost\smart_ptr\enable_shared_from_this.hpp(50)
: error C2243: 'type cast' : conversion from 'Request *' to
'boost::enable_shared_from_this<T> *const ' exists, but is inaccessible
1> with
1> [
1> T=Request
1> ]
1>
c:\boost\boost_1_40_0\boost\smart_ptr\enable_shared_from_this.hpp(48) :
while compiling class template member function 'boost::shared_ptr<T>
boost::enable_shared_from_this<T>::shared_from_this(void)'
1> with
1> [
1> T=Request
1> ]
1> c:\src\cpp\trunk\request_lib\request.h(48) : see reference to
class template instantiation 'boost::enable_shared_from_this<T>' being
compiled
1> with
1> [
1> T=Request
1> ]

Can I get this to work?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net