gpt4 book ai didi

c++ - 从模板类中获取 "sub-type"

转载 作者:太空狗 更新时间:2023-10-29 23:44:34 25 4
gpt4 key购买 nike

假设我有课

template<
typename T1, /*this is probably an integral type*/
T1 Default /*this is a typical value of that integral type*/
> class Foo {};

以及给定 T1Default 的实例化,例如 foo

我可以使用 decltype(foo) 来获取完整的类型。

我可以使用一些语法来获取值 Default 吗?

最佳答案

只需在类中使用typedef

template<
typename T1,
typename T2
> class Foo
{
public:
typedef T1 type1;
typedef T2 type2;
};

要获得默认值,您实际上可以使用相同的语法。

template<
typename T1,
T1 Default
> class Foo
{
public:
typedef T1 type1;
static constexpr const T1 default_value = Default;
};

关于c++ - 从模板类中获取 "sub-type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28066370/

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