Search code examples
c++templatestypename

Alias to complicated Template Typename


I have the following definition in file Segment.h

template<typename T, typename VecType = mat::vec3_gen<T> > class Segment
{
    // class
}

Instead of having typename VecType = mat::vec3_gen<T> I want to use some alias for the type and be able to use it outside the file also. how can I do it?


Solution

  • Since the type VecType depends on T, you can make the type alias a member of Segment.

    template<typename T>
    class Segment {
    public:
        using VecType = mat::vec3_gen<T>;
    };
    

    Now you can use it in other code:

    auto vec = Segment<int>::VecType;