1. 程式人生 > >c++模板學習

c++模板學習

很好的學習網站:

http://www.runoob.com/cplusplus/cpp-templates.html

 

1.模板格式:

template <class type> ret-type func-name(parameter list) { // 函式的主體 }

2.定義一個普通模板:

template <typename T>

3.定義一個類模板:

template <class type> 
class class-name {
    void func() const;
    .
    .
}

4.後續使用:

return_type class-name<type>::func() const

{

}