gpt4 book ai didi

c++ - 两个模板模板参数,其中一个需要另一个

转载 作者:行者123 更新时间:2023-12-02 01:55:54 25 4
gpt4 key购买 nike

这很难描述。我有一个带有两个模板模板参数的类 (Duo)。其中一个类是另一个类的参数,但它还没有完全定义,直到我们进入 Holder 中,然后我使用模板参数实例化 Solid只有持有者知道。

template<class T>
struct Solid
{
T _t;
};

template<template<typename> class SE>
struct Holder
{
SE<int> _se;
};

template<template<typename> class HOLD,
template<typename> class S>
struct Duo
{
HOLD<S> _mem;
};


int main()
{
Duo<Holder, Solid> a;
return 0;
}

但是,我收到此编译器错误:

   29 |     HOLD<S> _mem;
| ^
main.cpp:29:14: note: expected a type, got ‘S’

有办法实现这一点吗?

最佳答案

HOLD 的参数必须是模板而不是类型:

template<
template<template <typename> class> class HOLD,
template<typename> class S
>
struct Duo

关于c++ - 两个模板模板参数,其中一个需要另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69606929/

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