退货类型中不需要模板参数
No Template Parameter Needed in Return Type
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++) 项目希望我们创建两个构造函数,但它们都不需要任何参数 - 我应该在这里做什么?
- 为什么在这种特殊情况下我不需要模板参数?
- std::regex_replace 不需要少于 6 个参数
- 提供第二个可选参数,而不需要提供第一个可选参数
- 如何将成员函数作为参数传递给不需要它的函数?
- 通过使用不同的参数调用每个元素的非默认构造函数来初始化std::vector,而不需要进行不必要的复制
- C++函数调用后不需要的额外按引用传递参数的模式?
- 提升::池中不需要模板参数
- 函数还是函子作为模板参数?(如果不需要状态)
- 如果std::make_unique从未被调用,为什么它在默认成员初始化中不需要参数
- 纹理的SDL Renderer参数,但曲面不需要
- 在c++ 11中,是否有一种方法可以在调用以任何可调用对象(包括绑定方法)作为参数的函数时不需要模板参数
- 如何在c++中为不需要的参数使用占位符
- 为什么这个类定义中不需要空的参数列表
- 我可以使用google mock来检查方法参数而不需要预先设置期望吗?
- 传递静态方法作为参数,不需要地址操作符
- 当我不需要使用函数的所有参数时,我该怎么办?
- 如何创建一个不需要调用方向其传递参数计数的可变参数函数?