Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-05-23 08:28:49


Erik Thiele wrote:
> hi
>
> i use my own smartpointer class but hope to consolidate it into some
> other standard class some day (like the boost smart_ptr).
>
> an open point is the "this" pointer in classes. i have a problem with
> this situation:
>
> class myclass {
> void foo ();
> };
>
> void myclass::foo()
> {
> // i do not know, if there is a smartpointer on me.
> // in some situations i'd like to have it!
> // that's why "this" exists, but "this" is not a
> // smartpointer! so either i have to get it in my
> // parameter list, or i have to be derived from
> // some "smartpointable" base class and call the
> // thissmartptr() member function.
>
> // but how should i implement the "thissmartptr" function?
> // in the class construction, nobody gets the smartpointer.
> }

If you switch to shared_ptr, you can derive myclass from
enable_shared_from_this<myclass> to get access to the shared_from_this()
member function.

http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html


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