クラステンプレートのメンバ関数テンプレートを外部で定義する。
// 元のHogeクラステンプレート。 template <class T> struct Hoge { // メンバ関数テンプレートを宣言する。 template <class U> void Fuga(U val); }; // 定義。templateを二つ重ねて指定する! template <class T> template <class U> void Hoge<T>::Fuga(U val) { std::cout << "fuga;" << val << std::endl; }
ローカルクラステンプレートも。
template <class T> struct Hoge { // ローカルクラステンプレートを宣言する。 template <class V> struct Piyo; }; // 定義。 template <class T> template <class V> struct Hoge<T>::Piyo { V _val; Piyo(V val) : _val(val) { } };
これで、.hには宣言のみを書き、別の.hppとか.inlとかに定義を書き分ける事が出来て、
より見やすくなる(場合によっては見難いか・・・)