テンプレート #include <iostream> /* * * テンプレート * * テンプレートは汎用のデータ型を扱うことができる。 * 例えばテンプレートを用いた配列を扱うクラスでは、 * 配列の型がintであろうとcharであろうと対応する。 * */ template <class T> class A{ T a; public: A(T t){this->a = t;} void printT(); }; using namespace std; template <class T> void A<T>::printT(){ cout << this->a << endl; } int main(){ A<int> a(2); a.printT(); return 0; } 結果 2