Given a class template:
template <typename T>
class my_class
{
public:
my_class& test1() { return *this; }
// OR
my_class<T>& test2() { return *this; }
}
Is there any difference between return types of test1
and test2
?
Given a class template:
template <typename T>
class my_class
{
public:
my_class& test1() { return *this; }
// OR
my_class<T>& test2() { return *this; }
}
Is there any difference between return types of test1
and test2
?
Is there any difference between return types of
test1
andtest2
?
No. There is a concept called injected-class-name. Within the body of my_class<T>
, the name my_class
refers to the full type my_class<T>
.
We can even take this to its logical conclusion and add:
my_class::my_class::my_class::my_class& test4() { return *this; }
No, within the scope my_class<T>
, my_class
is an abbreviation for my_class<T>
.