クラステンプレートを使ってクラスを定義する
#include <iostream> using namespace std; template <class dtype1, class dtype2> class Sute { private: dtype1 a; dtype2 b; public: Sute(dtype1 a, dtype2 b) { // コンストラクタ this->a = a; this->b = b; } dtype2 conv() { return (dtype2)this->a; } }; int main(){ Sute <int, char> test1(65, '1'); // int型、char型でSuteクラスを実体化する。 cout << test1.conv() << endl; Sute <char, int> test2('A', 1); // char型、int型でSuteクラスを実体化する。 cout << test2.conv() << endl; return 0; }