Onkar N Mahajan
Onkar N Mahajan

Reputation: 437

What does 'template <typename> class X' mean?

Stan Lippman et. al (in "C++ Primer ", 5/e) , say :

  1 // forward declarations needed for friend declarations in Blob
  2 template <typename> class BlobPtr;
  3 template <typename> class Blob; // needed for parameters in operator==
  4 template <typename T>
  5     bool operator==(const Blob<T>&, const Blob<T>&);
  6 template <typename T> class Blob {
  7     // each instantiation of Blob grants access to the version of
  8     // BlobPtr and the equality operator instantiated with the same type
  9     friend class BlobPtr<T>;
 10     friend bool operator==<T>
 11            (const Blob<T>&, const Blob<T>&);
 12     // other members as in § 12.1.1 (p. 456)
 13 };

I didn't really understand template <typename> part in line 2 & 3. I tried to search, but couldn't find anything clear and substantial to read more about about template <typename>.

Please help me with some pointers for reading more about declarations such as

template <typename> class BlobPtr

Upvotes: 0

Views: 169

Answers (1)

eerorika
eerorika

Reputation: 238311

template <typename> class BlobPtr;

This is declaration of a class template. The name of the template is BlobPtr and it has one template type parameter.

Upvotes: 3

Related Questions