gpt4 book ai didi

c++ - 模板方法和模板类 C++

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:56:48 24 4
gpt4 key购买 nike

类成员函数可以是模板函数,还是必须是静态类函数。类和函数基本上可以按需在技术上分别实例化吗?

使用模板函数作为模板类的成员有什么限制?两者是否可以同时完成,或者是非此即彼?

最佳答案

你可以拥有模板类的模板成员函数,像这样:

template <typename T>
class Foo {
public:
template <typename U>
void bar(const T& t, const U& u);
};

template <typename T>
template <typename U>
void Foo<T>::bar(const T& t, const U& u) {
// ...
}

关于c++ - 模板方法和模板类 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7695084/

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