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

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 52', 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ả | addressof Header boost When taking the address of a variable we typically depend on the returned value to be well the address of the variable. However it s technically possible to overload operators which means that evildoers may be on a mission to wreak havoc on your address-dependent code. boost addressof is provided to get the address anyway regardless of potential uses and misuses of operator overloading. By using some clever internal machinery the template function addressof ensures that it gets to the actual object and its address. Usage To always be sure to get the real address of an object use boost addressof. It is defined in boost utility. hpp . It is used where operators would otherwise be used and it accepts an argument that is a reference to the type whose address should be taken. include boost class some_class int main some_class s some_class p boost addressof s Before seeing more details on how to use addressof it is helpful to understand why and how operators may not actually return the address of an object. Quick Lesson for Evildoers If you really really really need to overload operators or just want to experiment with the potential uses of operator overloading it s actually quite easy. When overloading operators the semantics are always different from what most users and functions expect so don t do it just to be cute do it for a very good reason or not at all. That said here s a code-breaker for you class codebreaker public int operator const return 13 With this class anyone who tries to take the address of an instance of codebreaker is handed the magical number 13. template typename T void print_address const T t std cout Address t n int main codebreaker c print_address c It s not hard to do this but are there good arguments for ever doing it in real code Probably not because it cannot be made safe except when using local classes. The reason for this is that while it is legal to take the address of an incomplete type it .

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.