cpp-best-practices / cpp-best-practices/cppbestpractices
Forward Declarations
- 主要語言
- 沒有語言資料
- 星號
- 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" 的文件區段,閱讀其周圍的指引以及所有連結的參考資料。更新該建議,以反映 issue 對 forward declarations 的疑慮,然後確認該區段內部一致,並清楚說明偏好的做法。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- cpp
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100