template (2)

#include <stdio.h>
template <class T, class M>
class Base {
    public:
        T x;
        T y;
        M a;
        M b;
    public:
        T max()
        {
            return (x>y) ? (x):(y);
        }
        M min()
        {
            return (a<b) ? (a):(b);
        }
};
void test()
{
    //Base<int, int> b;
    //Base<char, char> b;
    Base<int, char> b;
    b.x = 1;
    b.y = 2;
    b.a = 10;
    b.b = 20;
    int max = 0;
    max = b.max();
    int min = 0;
    min = b.min();
    printf("max: %d, min: %d\n", max, min);

}
int main(int argc, char **argv)
{
    test();
}

posted @ 2017-04-25 12:31  roadmap  阅读(98)  评论(0)    收藏  举报