zoukankan      html  css  js  c++  java
  • 自考新教材-p352_1

    源程序:

    #include <iostream>
    using namespace std;
    template <class T>

    class max
    {
    private:
    T x, y;
    public:
    max(T a, T b)
    {
    x = a;
    y = b;
    }
    T compare()
    {
    return (x > y) ? x : y;
    }
    };

    //template <class T>
    int main()
    {
    //T xx, yy;
    //cout << "请输入两个数:";
    //cin >> xx >> yy;
    max <int>m1(2, 4);
    cout << m1.compare() << endl;
    max <double>m2(3.5, 1.7);
    cout << m2.compare() << endl;
    max <char>m3('m', 'p');
    cout << m3.compare() << endl;
    system("pause");
    return 1;
    }

    运行结果:

  • 相关阅读:
    day_10作业
    day_10
    day_09
    day_08
    猜年龄游戏
    day_07
    day_06作业
    day05课堂小结
    day05作业
    day04课堂小结
  • 原文地址:https://www.cnblogs.com/duanqibo/p/12267301.html
Copyright © 2011-2022 走看看