gpt4 book ai didi

c++ - template 模板 有什么作用?

转载 作者:行者123 更新时间:2023-12-03 06:55:56 29 4
gpt4 key购买 nike

最近我偶然发现了这样一段代码:

template <typename Ta> template <typename Tb>
void SomeClass<Ta>::Function() {}
有模板函数,但它有奇怪的语法,我不太明白。它有什么作用?附近有没有 template<template<typename Ta>> ?
我从来没有遇到过这样的语法,我很困惑。

最佳答案

有时它只需要一个完整的例子:

template <typename Ta>
struct SomeClass {
template <typename Tb>
void Function();
};


template <typename Ta> template <typename Tb>
void SomeClass<Ta>::Function() {}

int main() {
SomeClass<int> sc;
sc.Function<double>();
}
它是类模板的方法模板的定义。

关于c++ - template<typename> 模板 <typename> 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63897269/

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