这段代码:
产生以下错误(使用GCC 6.3):
现在,我可以这样解决这个问题:
#include <memory>
template <template <typename> class Ptr>
class A { Ptr<int> ints; };
using B = A<std::unique_ptr>;
产生以下错误(使用GCC 6.3):
a.cpp:6:28: error: type/value mismatch at argument 1 in template parameter list for ‘template<template<class> class Ptr> class A’
using B = A<std::unique_ptr>;
^
a.cpp:6:28: note: expected a template of type ‘template<class> class Ptr’, got ‘template<class _Tp, class _Dp> class std::unique_ptr’
现在,我可以这样解决这个问题:
template <typename T>
using plugged_unique_ptr = std::unique_ptr<T>;
using B = A<plugged_unique_ptr>;
但我为什么要这样做呢?我的意思是,为什么编译器不愿意使用std::unique_ptr
的第二个模板参数默认值,并允许将std::unique_ptr
用作A
的模板实参?
C++17
以来的版本。 - HolyBlackCat