2010-09-05から1日間の記事一覧

配列の要素数を返すテンプレート関数

C++

C++テンプレートテクニックの2-4より. #include <iostream> using namespace std; template <class T, int N> int size(T (&x)[N]) { return N; } int main(int argc, char const* argv[]) { int a[] = {1, 2, 3, 4, 5}; cout << size(a) << endl; return 0; } 出力結果 5これは面白い</class></iostream>…