如何解决如何扩展依赖类型的参数包?
扩展参数包的语法是什么,我想要的类型直接取决于参数包中的类型?
例如:
template <typename T>
struct foo
{
typedef T value_type;
};
template <typename ... T>
struct aggregate_of_foo
{
typedef std::tuple<foo<T>::value_type...> tuple; // MSVC compiler error here
};
解决方法
如果您在foo
中使用bar
而不是typedef
,则之前只是缺少typename
关键字:
template <typename ... T>
struct aggregate_of_foo
{
using tuple_foo = std::tuple<typename foo<T>::value_type...>;
// ^^^^^^^^
};
还请注意,我将其命名为tuple_foo
,因为这比仅拥有tuple
更有意义。
您必须使用关键字typename
,因为在这种情况下value_type
是一个从属名称。
template <typename ... T>
struct aggregate_of_foo
{
typedef std::tuple<typename foo<T>::value_type...> tuple; //here
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。