TAILIEUCHUNG - HandBooks Professional Java-C-Scrip-SQL part 48

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 48', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | void failure_is_error base1 p try some_other_class soc dynamic_cast some_other_class p Use soc catch std bad_cast e std cout n void failure_is_ok base1 p if some_other_class psoc dynamic_cast some_other_class p Use psoc In this example the pointer p is dereferenced15 and the target type of the conversion is a reference to some_other_class. This invokes the throwing version of dynamic_cast. The second part of the example uses the nonthrowing version by converting to a pointer type. Whether you see this as a clear and concise statement of the code s intent depends upon your experience. Veteran C programmers will understand the last example perfectly well. Will all of those reading the code be sufficiently familiar with the workings of dynamic_cast or is it possible that they ll be unaware of the fact that it works differently depending on whether the type being converted is a pointer or reference Will you or a maintenance programmer always remember to test for the null pointer Will a maintenance programmer realize that dereferencing the pointer is necessary to get the exception if the conversion fails Do you really want to write the same logic every time you need this behavior Sorry for this rhetoricits intent is to make it painfully obvious that polymorphic_cast makes a stronger clearer statement than dynamic_cast when a conversion failure should result in an exception. It either succeeds producing a valid pointer or it fails throwing an exception. Simple rules are easier to remember. 5 If the pointer p is null the example results in undefined behavior because it will dereference a null pointer. We haven t looked at how you can overload polymorphic_cast to account for unusual conversion needs but it should be noted that it s possible. When would you want to change the default behavior of a polymorphic cast One example is for handle body-classes where the rules for downcasting may be different from the default or should be disallowed altogether. Summary It is

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.