template stuff in C++

1. Template function 

template <class T> // a template prefix
T func(T a, T b, T c){ // return value is T type, 3 T-typed formal parameters
   return a + b + c;
}

We could also specify different types here: 

template <class T1, class T2, class T3>
T1 func(const T1& a, const T2& b, const T3& c){ // passing 3 different types of formal parameter
   return a + b + c; // return value is T1-typed
}

 

posted @ 2014-11-24 05:32  Rui Yan  阅读(148)  评论(0编辑  收藏  举报