前方宣言とは?
前方宣言は、コンパイラが完全な定義を見る前に参照できるよう、型や関数の名前と基本的な形を導入します。ポインタやシグネチャだけを必要とする用途には十分で、完全なレイアウトは要りません。型の詳細を必要とするコードの前には、完全な定義がやはり現れなければなりません。
なぜ重要か
前方宣言はインクルードの循環を断ち、コンパイルの依存関係を減らし、ビルドの高速化と結合の低減につながります。また、そうでなければ定義できない相互参照する型を可能にします。
関連ガイド
What Is a Header Guard?A header guard is a preprocessor pattern that ensures a header file is included only once per translation uni…
What Is a Translation Unit?A translation unit is the complete source seen by the compiler after preprocessing one source file, the unit…
What Is Template Instantiation?Template instantiation is the compiler generating concrete code from a generic template for each specific set…