Search code examples
c++templatescompiler-errorstypedefusing

C++ - Template + 'using' clause - mismatch argument error


I'm trying to use a template and two typedef, but I know that the only way is to insert a 'using' clause like that:

template<typename T>
using Car = std::pair<T, T>;
using SparseMatrix = std::vector< Car >;

The problem is that gcc gives me the following error:

error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’

I think the problem is that Car is not a type because of the 'using' clause. How can I resolve?


Solution

  • Car is an alias template, so you need to take a template argument in SparseMatrix and forward it on:

    template <typename T>
    using SparseMatrix = std::vector<Car<T>>;