5

I thought this would be easy, but it's not working the way I expected. What is the correct syntax here?

TemplateClass.h

template <typename T> 
class TemplateClass
{
  T & operator[](size_t n);

TemplateClass.cpp

#include "TemplateClass.h"

template <typename T>
T & TemplateClass::operator[](size_t n)
{
  // member declaration not found
}
Sharp Steel Software
  • 4,789
  • 4
  • 37
  • 89

1 Answers1

7

You need to provide the whole class name – including template arguments:

template <typename T>
T & TemplateClass<T>::operator[](size_t n)
{
  // ...
}

(Also note that the scope resolution operator is ::, not :.)

maxywb
  • 1,935
  • 17
  • 25
Konrad Rudolph
  • 506,650
  • 124
  • 909
  • 1,183