2009-05-01から1ヶ月間の記事一覧

テンプレートに文字列を渡してみる。

C++

テンプレートパラメータに指定できるもの - Faith and Brave - C++で遊ぼう にある通り、テンプレートにはポインタが渡せると言う事で、 以下の様に文字列等を渡してみる。 #include <iostream> // 文字列 (char*) char hoge[] = "hoge"; static char fuga[] = "fuga";</iostream>…

クラステンプレートのメンバ関数テンプレートを外部で定義する。

C++

// 元の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 <</t></class></class></class></class>…