Returning a shared_ptr or raw pointer from a template function
I want to allow the user to specify if a function returns a raw pointer
or a shared_ptr from a creation type function. The code I've started
with is as follows:
class Track{};
class Tm{};
template
AMDG Ryan McConnehey wrote:
I would like to have a class that has this create function and upon creation of the class specify if the create function returns a raw pointer or shared_ptr.
template <class U> //The U specifies is the create function returns a raw or shared pointer class Rdi { template <class S> U create(void) { U temp(new S()); return temp; } };
How would I modify this class to allow the user to make the following calls?
Rdiboost::shared_ptr fun1;
This won't compile because boost::shared_ptr is a class template.
Tm* tm3 = fun1.create<Tm>();
Rdi
fun2; boost::shared_ptr<Tm> tm4 = fun2.create<Tm>(); Any help would be appreciated.
Try
#include
participants (2)
-
Ryan McConnehey
-
Steven Watanabe