Adrian B.
Adrian B.

Reputation: 185

Use class templates inside another class template

Let's say I have some classes using templates like the following in some file(s) :

    // PointerTemplates.hpp    

    template <class T>
    class Smart_Ptr_A
    {
      // [...]
    };

    template <class T>
    class Smart_Ptr_B
    {
      // [...]
    };

I would like to create another templated class that can use any of the previous classes.
Something like :

    // ClassFoo.hpp

    class ClassBar;

    template<class PtrType>
    class ClassFoo
    {
      // [...]
      PtrType<ClassBar> m_pBar;
    };

How could I do that ?

Upvotes: 0

Views: 703

Answers (1)

R Sahu
R Sahu

Reputation: 206727

You will need to use a template template parameter.

template <template<class> class PtrType>
class ClassFoo
{
  // [...]
  PtrType<ClassBar> m_pBar;
};

Upvotes: 3

Related Questions