1

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?

vladon
  • 8,158
  • 2
  • 47
  • 91

2 Answers2

7

Is there any difference between return types of test1 and test2?

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; }
Community
  • 1
  • 1
Barry
  • 286,269
  • 29
  • 621
  • 977
2

No, within the scope my_class<T>, my_class is an abbreviation for my_class<T>.

aschepler
  • 70,891
  • 9
  • 107
  • 161