Creating a type alias for a templated class

后端 未结 3 1780
小鲜肉
小鲜肉 2020-12-31 16:35

Instead of using

std::vector ObjectArray;


I would like it to be

MyArray ObjectArray;

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 17:03

    As of C++11 you can use a templated type alias

    template 
    using MyArray = std::vector;
    

    If you want to be more generic you can use a variadic template (which would allow for allocators in the case of vector without having to be specific)

    template 
    using MyArray = std::vector;
    

提交回复
热议问题