简体   繁体   中英

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
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM