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. } void main() { // sp is the smartpointer sp<myclass> m (new myclass()); // does this kind of initialisation still work // when the thissmartptr stuff shall be implemented? } i have no clue on how to implement the thissmartptr problem. my problems are class construction. do you have any plans, or is it even already implemented in the smart_ptr? cu & thx erik -- Erik Thiele
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
participants (2)
-
Erik Thiele
-
Peter Dimov