template的简单例子

来源:互联网 发布:C语言中感叹号 编辑:程序博客网 时间:2024/05/18 02:34
  1. #include<iostream>
  2. using namespace std;
  3. template <class T>
  4. int compare(const T &v1,const T &v2)
  5. {
  6.     if(v1==v2)
  7.         return 0;
  8.     if(v1>v2)
  9.         return -1;
  10.     if(v1<v2)
  11.         return 1;
  12. }
  13. void main()
  14. {
  15.     cout<<compare(10,5)<<endl;
  16.     cout<<compare(3.14,9.12)<<endl;
  17. }
原创粉丝点击