0

Is there a way to typedef a templatized struct in C++? For instance something like:

template <typename T>
struct mylist
{
  std::vector<T> contents;
  // ... other members
};

typedef struct mylist<T> * List<T>; // this is illegal

My goal is to hide the fact that my List is a pointer such that I can write code like:

List<int> intList;
List<char> charList;
JRR
  • 6,014
  • 6
  • 39
  • 59

1 Answers1

2

You can use alias template (since C++11). E.g.

template <typename T>
using List = mylist<T> *;

Then

List<int> intList;   // -> mylist<int> *
List<char> charList; // -> mylist<char> *
songyuanyao
  • 169,198
  • 16
  • 310
  • 405