zoukankan      html  css  js  c++  java
  • 类模板

    #include<iostream>
    using namespace std;
    template<class T>
    class compare{
    public:
    compare(T aa,T bb):a(aa),b(bb){}
    void update1();
    void update2();
    void update3();

    private:
    T a,b;
    };

    template<class T>
    void compare<T>::update1()
    {
    if(a<b)
    {
    cout<<b<<" is the Maximum of two inteder numbers."<<endl;
    cout<<a<<" is the Minimum of two inteder numbers."<<endl;
    }
    else
    {
    cout<<a<<" is the Maximum of two inteder numbers."<<endl;
    cout<<b<<" is the Minimum of two inteder numbers."<<endl;
    }
    cout<<endl;
    }

    template<class T>
    void compare<T>::update2()
    {
    if(a<b)
    {
    cout<<b<<" is the Maximum of two float numbers."<<endl;
    cout<<a<<" is the Minimum of two float numbers."<<endl;
    }
    else
    {
    cout<<a<<" is the Maximum of two float numbers."<<endl;
    cout<<b<<" is the Minimum of two float numbers."<<endl;
    }
    cout<<endl;
    }

    template<class T>
    void compare<T>::update3()
    {
    if(a<b)
    {
    cout<<b<<" is the Maximum of two characters."<<endl;
    cout<<a<<" is the Minimum of two characters."<<endl;
    }
    else
    {
    cout<<a<<" is the Maximum of two characters."<<endl;
    cout<<b<<" is the Minimum of two characters."<<endl;
    }
    }

    int main(){
    int x1,y1;
    cin>>x1>>y1;
    compare<int>ii(x1,y1);
    ii.update1 ();

    float x2,y2;
    cin>>x2>>y2;
    compare<float>ff(x2,y2);
    ff.update2();

    char x3[30],y3[30];
    cin>>x3>>y3;
    compare<char>cc(x3[1],y3[1]);
    cc.update3();
    return 0;
    }

  • 相关阅读:
    ASM FailGroup验证
    oracle 11g RAC 补丁升级方法
    数据库优化一
    TypeScript(类—继承—多态)
    TypeScript(安装配置—数据类型—函数)
    IE9兼容
    移动端自适应vw、vh、rem
    npm命令随笔
    安卓、IOS兼容问题
    获取页面大小和元素位置offset、client、scroll
  • 原文地址:https://www.cnblogs.com/zeross/p/4613368.html
Copyright © 2011-2022 走看看