![](/img/trans.png)
[英]c++ : how does std::bind() 'know' whether the template args refer to a static function or member function?
[英]What does “a member template of a class” refer to in the C++ standard?
C ++標准規定:
模板定義了一組類或函數。
template-declaration: exportopt template < template-parameter-list > declaration
模板聲明中的聲明應
- 聲明或定義函數或類,或者
- 定義類模板或嵌套在類模板中的類的成員函數,成員類或靜態數據成員,或
- 定義類或類模板的成員模板。
這些要點中的第三個使我感到困惑。 在這種情況下,“類的成員模板”的示例是什么? 成員函數或嵌套類定義將包含在前兩個類別之一中。 當然,沒有像模板數據成員這樣的東西嗎? 這是指typedef嗎?
類的成員模板是成員函數,其本身就是模板,如下所示:
class test {
template <typename T> void foo(); // member template of class
};
template <typename T>
void test::foo<T>() {} // definition
template <typename T>
class test2 {
template <typename U> void foo(); // member template of class template
};
template <typename T>
template <typename U>
void test2<T>::foo<U>() {} // definition
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.