
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday 15 May 2010, Philip Warner wrote:
And yes, this is sloppy, but in our case we have a set of interfaces that want to implement variant function return types based on derived class pointers, and we can not do that by returning shared_ptr objects. We need to return raw pointers, then rewrap them.
Are you saying you want to have a covariant return types with shared_ptr? Have you considered doing something like the following (completely untested): class Base { typedef X FReturnType; private: template<typename T> friend shared_ptr<T::FReturnType> g(T &t); virtual FReturnType* f(); }; class Derived: public Base { public: typedef DerivedFromX FReturnType; private: template<typename T> friend shared_ptr<T::FReturnType> g(T &t); virtual FReturnType* f(); } template<typename T> shared_ptr<typename T::FReturnType> g(T &t) { return shared_ptr<typename T::FReturnType>(t.f()); } -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkvxQqIACgkQ5vihyNWuA4WqXACcCVjVolqyngjpqlZyIsuN6bTR XY4Anj5sz8ZrcZ7l/Eih+iPsKYa7nGyY =w5TK -----END PGP SIGNATURE-----