cpp-best-practices / cpp-best-practices/cppbestpractices
Forward Declarations
- Lenguaje dominante
- Sin datos de lenguaje
- Estrellas
- 8.8k
- Forks
- 902
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza localizando la sección de la documentación titulada "Forward Declare When Possible" y leyendo las indicaciones que la rodean y cualquier referencia enlazada. Actualiza la recomendación para reflejar las preocupaciones del issue sobre las forward declarations y, después, confirma que la sección sea internamente coherente y exponga claramente la práctica preferida.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- cpp
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100