Forward Declarations

Đang mở
#89 1 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
documentation

Hướng nghiên cứu

Bắt đầu bằng cách xác định phần tài liệu có tiêu đề "Forward Declare When Possible" và đọc hướng dẫn xung quanh phần đó cùng mọi tài liệu tham chiếu được liên kết. Cập nhật khuyến nghị để phản ánh những mối quan ngại của issue về forward declarations, sau đó xác nhận rằng phần này nhất quán về mặt nội tại và nêu rõ thực hành được ưu tiên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
8.9k
Fork
903
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của cpp-best-practices/cppbestpractices

Tất cả issue của cpp-best-practices/cppbestpractices

Issue tương tự

Thêm issue về Documentation

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.