Reputation: 25551
template <typename Type>
class Foo
{
Foo& Bar()
{
return *this;
}
};
Why does this compile? Shouldn't I have to specify the template parameter in the return type?
Foo<Type>& Bar()
{
return *this;
}
Upvotes: 2
Views: 142
Reputation: 35925
Foo<Type>
is implied because the definition of Bar
is within the definition of the class. If it were outside the class definition then you'd have to define it explicitly:
template <typename Type>
Foo<Type>& Foo<Type>::Bar()
{
return *this;
}
Upvotes: 2