gpt4 book ai didi

c++ - 模板模板部分特化失败 : "expected a class template"

转载 作者:行者123 更新时间:2023-11-30 02:30:29 25 4
gpt4 key购买 nike

此示例代码生成 expected a class template, got std::pair <_T1, _T2> .我尝试使用 struct Struct <std::pair> {}; ,然后是参数 TM变得不可推卸。如何避免这种情况?

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

template <class T, class M>
struct Struct <std::pair <T, M>> {};

最佳答案

根据自己的需要

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

template <>
struct Struct <std::pair>
{
// Specialization
};

template <typename> struct Struct {};

template <typename First, typename Second>
struct Struct <std::pair<First, Second>>
{
// Specialization
};

关于c++ - 模板模板部分特化失败 : "expected a class template",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38562682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com