加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 使用类型别名如何指定依赖于模板参数的模板模板参数?

发布时间:2020-12-16 09:56:30 所属栏目:百科 来源:网络整理
导读:参见英文答案 Where and why do I have to put the “template” and “typename” keywords?????????????????????????????????????6个 最小的例子: templatetemplateclass ... classstruct templ {};templateclass Tusing special = templT::type;int main
参见英文答案 > Where and why do I have to put the “template” and “typename” keywords?????????????????????????????????????6个
最小的例子:

template<template<class ...> class>
struct templ {};

template<class T>
using special = templ<T::type>;

int main() {}

clang:

test.cpp:5:23: error: template argument for template template parameter must be a class template or type alias template
using special = templ<T::type>;

实际上,我的意思是说T :: type是一个类模板,例如

struct detail1 {
    template <class T>
    using type = std::vector<T>;
};

struct detail2 {
    template <class T>
    struct type {};
};

但是怎么能这么说呢? g建议使用typename T :: type,但这对我来说是错误的,事实上,这并不能解决错误.

解决方法

您需要指定该类型是模板:

template<class T>
using special = templ< T::template type>;

这是必需的,因为T :: type依赖于模板参数T.

另见Where and why do I have to put the “template” and “typename” keywords?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读