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
}

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
  • 2,275
  • 1
  • 19
  • 25
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214