gpt4 book ai didi

c++ - 这是什么模板?

转载 作者:太空宇宙 更新时间:2023-11-04 12:05:09 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?

这是片段代码:

template <typename alloc_t>
int Protocol_v2<alloc_t>::create(..., alloc_t *alloc, ...) {
Protocol_v2<alloc_t> * pack = alloc->template malloc<Protocol_v2<alloc_t> >();

Protocol_v2是一个模板类,如下:

    template <typename alloc_t>
class Protocol_v2 { ...}

alloc_t是一个类,如下:

class reverse_allocator { 
...
template<typename T>
inline T * malloc() {}
...
}

困扰我的是这一行:

Protocol_v2<alloc_t> * pack = alloc->template malloc<Protocol_v2<alloc_t> >();

这是什么意思?到目前为止,我还没有在 C++ 入门中看到这一点。

提前致谢。

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