提问人:Ad N 提问时间:7/22/2021 最后编辑:Ad N 更新时间:7/22/2021 访问量:171
模板类型是否有等效的“typename”?[复制]
Is there an equivalent of "typename" for template types? [duplicate]
问:
我们有一个表单的模板成员函数:
template <template <class> class TT>
TT<some_type> foo() const;
现在,在从依赖名称显式指定 TT 的调用上下文中:
template <class T_other>
void bar()
{
instance.foo<T_other::template_type>();
}
Visual Studio 能够编译调用。海湾合作委员会抱怨:
error: dependent-name ‘SomeConcreteType::template_type’ is parsed as a non-type, but instantiation yields a type.
并建议说.这是行不通的,因为是模板类型,而不是普通类型。typename SomeConcreteType::template_type
SomeConcreteType::template_type
- 这里有可以使用的关键字吗?
- 另一种方法可以让三大编译器接受它?
编辑:现在有一个 Godbolt 最小示例 https://godbolt.org/z/hvbb6jv9W
答:
2赞
HTNW
7/22/2021
#1
使用代替 .而且,请注意,while 会在 之前 ,之后。template
typename
typename
::
template
template<class T_other>
void bar() {
instance.foo<T_other::template template_type>();
}
评论
0赞
Ad N
7/22/2021
您在最小示例到来之前提供了解决方案,恭喜!
评论
template
?...instance.foo<T_other::template_type>();
->instance.foo<typename T_other::template_type>();
T_other
typename SomeConcreteType::template_type
template <template <class> class TT>
class
TT
)