【初心者歓迎】C/C++室 Ver.50【環境依存OK】at TECH
【初心者歓迎】C/C++室 Ver.50【環境依存OK】 - 暇つぶし2ch320:デフォルトの名無しさん
08/03/04 17:05:25
>>310
多分、テンプレート関数では配列の一部を出力してその有無を返すだけと判断して勝手に修正してみた。
--
#include <iostream>
using namespace std;

template<class T> bool show_array(T array[], int N)
{
for (unsigned ic = 0; ic < N; ++ic) {
cout << array[ic] << ' ';
}
return N != 0;
}

int main( void )
{
int pages[] = { 100, 200, 300, 400, 500 };
float price[] = { 10.05, 20.10, 30.15 };

/* int型の配列 */
show_array( pages, 5 );
cout << '\n';

/* float型の配列 */
cout << show_array( price, 3 ) << endl;
cout << show_array( price, 0 ) << endl;
cout << '\n';

return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch