gpt4 book ai didi

c++ - 指针的部分特化,C++

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:08:33 25 4
gpt4 key购买 nike

如何对类 GList 进行部分特化,以便可以存储 I(即 I*)的指针?

template <class I>
struct TIList
{
typedef std::vector <I> Type;
};


template <class I>
class GList
{
private:
typename TIList <I>::Type objects;
};

最佳答案

您无需专门化即可实现这一点。它已经可以存储指针。

GList<int*> ints;

无论如何,如果您想为指针特化 GList,请使用以下语法。

template <class I>
class GList<I*>
{
...
};

然后只需使用 I就像在任何普通模板中一样。在上面的例子中 GList<int*> ,将使用指针特化,并且 I将是 int .

关于c++ - 指针的部分特化,C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4764188/

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