【发布时间】:2018-04-11 00:51:18
【问题描述】:
以下代码无法编译并出现类型/值不匹配错误,但我知道提供了一个类型。我错过了什么?
template<typename A, typename B>
struct base {};
template<typename B>
struct derived : base< derived<B>::type, B >
{
using type = int;
}
int main()
{
derived<char> d;
}
error: type/value mismatch at argument 1 in template parameter
list for 'template<class A, class B> struct base'
struct derived : base< derived<B>::type, B >
note: expected a type, got 'derived<B>::type'
为什么derived<B>::type 不是有效类型?
此外还尝试了以下方法:
template<typename B>
struct derived : base< typename derived<B>::type, B >
{
using type = int;
}
并得到以下错误:
no type name 'type' in 'struct derived<char>'
为什么编译器检测不到类型?
【问题讨论】:
标签: c++ templates inheritance