gpt4 book ai didi

c++ - 返回类型中不需要模板参数

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

template <typename Type>
class Foo
{
Foo& Bar()
{
return *this;
}
};

为什么要编译?我不应该在返回类型中指定模板参数吗?

Foo<Type>& Bar()
{
return *this;
}

最佳答案

Foo<Type>是隐含的,因为 Bar 的定义在类的定义内。如果它在类定义之外,那么您必须明确定义它:

template <typename Type>
Foo<Type>& Foo<Type>::Bar()
{
return *this;
}

关于c++ - 返回类型中不需要模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6529874/

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