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
  • 7,870
  • 1
  • 42
  • 82

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
  • 267,863
  • 28
  • 545
  • 906
2

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

aschepler
  • 68,873
  • 9
  • 101
  • 151