cpp-best-practices / cpp-best-practices/cppbestpractices

Forward Declarations

オープン
#89 コメント 1 件 リアクション 2 件 担当者 0 名 GitHub で見る
主要言語
言語のデータがありません
スター
8.8k
フォーク
902
PR マージ指標
30日以内にマージされた PR はありません

説明

Regarding "Forward Declare When Possible", I think you should (almost) never forward declare for the following reasons:

1. It makes backward compatible refactorings more complicated and prone to breakage. This is the reason that the the C++ Standard Library and abseil forbid forward declarations. In C++ you can often refactor a function into a lambda or function object or into a template and keep backward compatibility with uses of the function. However, the signature will have changed.

2. It is dangerous. Forward declarations are an easy way to get hard to diagnose errors like ODR violations. In addition, if something changed in a header you were depending on, forward declarations postpone the error to link-time or to compile time.

3. It is a short term optimization. Hopefully modules in C++ will come soon and make this better. But even without modules, such techniques as pre-compiled headers are safer and work in more scenarios.

Based on these, I think better advice would be to avoid forward declarations.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず、"Forward Declare When Possible" というタイトルのドキュメントセクションを見つけ、その周辺のガイダンスとリンクされた参照をすべて読んでください。forward declarations に関する issue の懸念を反映するように推奨事項を更新し、そのうえで、セクション内に一貫性があり、推奨される実践方法が明確に示されていることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp
領域
documentation
issue の種類
ドキュメント
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。