Hi
I have a third party code.
class Lazy
{
protected:
template <class T>
static void create( T*& ptr )
{
ptr = new T;
}
};
template < class ClassT,
class Policy=Lazy
>
class MakeT : private Policy
{
public:
static ClassT* instance()
{
static ClassT* ptr = 0;
if(!ptr)
Policy::create(ptr);
return const_cast<ClassT*>(ptr);
}
};
Above is used to create new instance of a class.
What I could not understand here is class Lazy. Here why need to use such class? Why code
if(!ptr)
Policy::create(ptr);
could not replace with
if(!ptr)
ptr = new ClassT;
Why need of having Lazy class? And why *& used in
static void create( T*& ptr )
method
Thanks