泛型类型

#include <iostream>
using namespace std;

template<typename T>
class Size {
public:
    T width;
    T height;

    Size(T width, T height) {
        this->width = width;
        this->height = height;
    }

    string asText() {
        char style[30];
        snprintf(style, 30"[%f; %f]",
            (double)width, (double)height);
        return style;
    }
};

Size<intsizeInt(58);
string textInt = sizeInt.asText();
//textInt is "[5.000000; 8.000000]"

Size<floatsizeFloat(3.71.58);
string textFloat = sizeFloat.asText();
//textFloat is "[3.700000; 1.580000]"

cout << "textInt is " << textInt << "\n";
cout << "textFloat is " << textFloat;