Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial specialization for pointers, c++

How to make partial specialization of the class GList so that it is possible to store pointers of I (i.e I*) ?

template <class I>
struct TIList
{
    typedef std::vector <I> Type;
};


template <class I>
class GList
{
      private:
            typename TIList <I>::Type objects;
};
like image 934
Woody Avatar asked Dec 17 '22 18:12

Woody


1 Answers

You don't need to specialise to allow that. It can store pointers already.

GList<int*> ints;

Anyway, if you wanted to specialise GList for pointers, use the following syntax.

template <class I>
class GList<I*>
{
    ...
};

Then just use I as you would in any normal template. In the example above with GList<int*>, the pointer specialisation would be used, and I would be int.

like image 102
Peter Alexander Avatar answered Dec 26 '22 00:12

Peter Alexander