簡體   English   中英

&#39;模板是什么意思<typename> X班&#39;是什么意思?

[英]What does 'template <typename> class X' mean?

斯坦·利普曼等 al (in "C++ Primer ", 5/e) ,說:

  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 };

我並沒有真正理解第 2 行和第 3 行中的template <typename>部分。我嘗試搜索,但找不到任何清晰和實質性的內容來閱讀有關template <typename>更多信息。

請幫助我提供一些關於閱讀更多關於聲明的指示,例如

template <typename> class BlobPtr
template <typename> class BlobPtr;

這是類模板的聲明。 模板的名稱是BlobPtr ,它有一個模板類型參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM