-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 06 February 2007 10:23 am, Douglas Gregor wrote:
On Feb 5, 2007, at 6:28 PM, Timmo Stange wrote:
I understand your dilemma, but this can't be solved unless we decide to use something completely different from shared_ptr. The idea is that by connecting a slot to a signal, the lifetime tracking of bound objects is started and as soon as all shared_ptr references go out of scope, the slot is disconnected. Even if we could open up a loophole, you could never start tracking from the constructor itself, as the external shared_ptr reference to your object is only initialized when the constructor returns. You would need a second call to the member function to start tracking, in which case you can just as well set up the connection there.
Does enable_shared_from_this help at all?
You know I think it might, at least using a modified or derived version of it. Apparently, shared_ptrs will call into objects derived from enable_shared_from_this in order to set their _internal_weak_this weak_ptr. If we could hook into that call, we could have it call a virtual function called postconstruct(), and voila! We have a postconstructer where signals can be connected to member functions with tracking, and there is no danger of a slot being called before the object is fully constructed. Subclassing works relatively well too, the subclass just has to be sure to call its base class' postconstruct() call if it overrides it. - -- Frank -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFFyNYM5vihyNWuA4URApaFAJ9uj68vrc9gcKB7KLtCipu+GSOwvwCfQeR/ msXvI0fBodbvcpZD3K56++4= =t3rZ -----END PGP SIGNATURE-----