Forward Declarations
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- cpp
- Domain
- documentation
Research direction
Start by locating the documentation section titled "Forward Declare When Possible" and read its surrounding guidance and any linked references. Update the recommendation to reflect the issue's concerns about forward declarations, then confirm the section is internally consistent and clearly states the preferred practice.
Written by the indexing model from the issue text.
Description
Regarding "Forward Declare When Possible", I think you should (almost) never forward declare for the following reasons:
-
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.
-
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.
-
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.
- Dominant language
- No language data
- Stars
- 8.9k
- Forks
- 901
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cpp-best-practices/cppbestpractices
-
Broken Link Chapter 2: Use_the_Tools_AvailableMay be free again @vishesharma20 claimed this 191 days ago, and no pull request is open. Open
Difficulty 1/5 Under an hour Newbie friendliness 64/100
cpp-best-practices/cppbestpractices#169 · 1 comment ·
-
Broken Link - 11 Further ReadingPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 55/100
cpp-best-practices/cppbestpractices#168 · 1 comment ·
-
C++ PracticeOpen
Difficulty 5/5 Over a week Newbie friendliness 10/100
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
cpp-best-practices/cppbestpractices#160 · 1 comment ·
All issues in cpp-best-practices/cppbestpractices
Similar issues
-
area/network kind/documentation triage/needs-human
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
canonical/k8s-snap#3533 · 1 comment ·
Maintainers usually reply within 1 day
-
Feature:Actions/ConnectorTypes Team:ResponseOps
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
elastic/kibana#309028 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
DISIC/teleservice-conformite#230 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
cpp-best-practices/project_validator#609 ·
Maintainers usually reply within 1 day