2006-11-27から1日間の記事一覧

挿入ソートをテンプレートにしたもの

#include <stdio.h> template<class TYPE> void Sort(TYPE a[], int n) { int i, j; for(i = 1; i < n; i++){ j = i; while(j > 0 && a[j] < a[j-1]){ Swap(a[j], a[j-1]); j--; } } } template<class TYPE> void Swap(TYPE& a, TYPE& b) { TYPE tmp = a; a = b; b = tmp; } int main() { int </class></class></stdio.h>…

普通の関数とテンプレートの関数の呼び出しの優先順位を調べるテスト

#include <stdio.h> void Func(float f1, float f2) { printf("普通の関数が呼ばれました\n"); } template<class TYPE> void Func(TYPE f1, TYPE f2) { printf("テンプレート関数が呼ばれました\n"); } int main() { Func(5.5f, 7.5f); Func(5, 7); Func(5.5f, 7); Func<int>(5.5f, 7);</int></class></stdio.h>…

関数テンプレート

#include <stdio.h> template<class TYPE> void Swap(TYPE& a, TYPE& b) { TYPE tmp = a; a = b; b = tmp; } int main() { int n1 = 5, n2 = 7; Swap(n1, n2); printf("交換後:(n2, ,2) = (%d, %d)\n", n1, n2); float f1 = 5.5, f2 = 7.5; Swap(f1, f2); printf("交換後:(f1, f</class></stdio.h>…

Effective C++ 原著第3版 (ADDISON-WESLEY PROFESSIONAL COMPUTING SERIES)

Effective C++ 原著第3版 (ADDISON-WESLEY PROFESSIONAL COMPUTING SERIES)作者: スコット・メイヤーズ,小林健一郎出版社/メーカー: ピアソン・エデュケーション発売日: 2006/04/29メディア: 大型本購入: 29人 クリック: 411回この商品を含むブログ (186件) …

構文解析とは?

構文解析とは、トークンをいくつか集めて、指定された順番に並んでいるかをチェックする処理である。しかし、一般の言語 (プログラミング言語や、自然言語など)は、ただその順番を規定するだけではその構造を規定する(文法という)ことはできない。その文法を…

字句解析とは?

字句解析とは、コンパイラの中で最初に処理する部分である。そのため、 `生'のプログラム(ユーザが書いたプログラム、ソースプログラムという) を入力とする。例えば、C言語のソースプログラム、 main() { printf( "hello world!\n" ); } に対して、main、(…