Topic: Notification function for shared_from_this for when
Author: "'Johannes Schaub' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Mon, 16 May 2016 17:51:07 +0200
Raw View
I was thinking about constructors of classes that derive from
enable_shared_from_this. A problem with these classes is that the
shared_from_this() function is not available from the constructor,
because only afterwards, the object will be owned by a shared_ptr
class F : public enable_shared_from_this {
public:
F() {
doSomething(shared_from_this());
}
}
int main() { std::make_shared<F>(); }
The code is broken. However, if shared_ptr called a function after it
attached to F, this can be written
class F : public enable_shared_from_this {
private:
virtual void attached() {
doSomething(shared_from_this());
}
}
int main() { std::make_shared<F>(); }
What are your thoughts on this?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANu6V4XgJ7BynS4fCdXOLuAs17D2p_Q3Xh9WJhboYOd92i9Mdg%40mail.gmail.com.
.