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

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 65', 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ả | std cout This any contained a boost shared_ptr A n ptr- is_virtual ptr- not_virtual return catch boost bad_any_cast e Try boost shared_ptr B try boost shared_ptr B ptr boost any_cast boost shared_ptr B a std cout This any contained a boost shared_ptr B n ptr- is_virtual ptr- not_virtual return catch boost bad_any_cast e If anything else like just a string ignore it std cout The any didn t contain anything that concerns this function n In main we create two anys at function scope. We then introduce a new scope and create two new anys. Next we store all of the anys in the vector and send every element in it to the function foo which examines their contents and exercises them. It should be duly noted that we are actually violating the advice that was given earlier to use the pointer form of any_cast when a failure does not designate an error. However because we are dealing with smart pointers here the syntactic advantage of using the exception-throwing form of any_cast is reason enough to ignore the advice this time. int main std cout Example of any and shared_ptr n boost any a1 boost shared_ptr A new A boost any a2 std string Just a string boost any b1 boost shared_ptr A new B boost any b2 boost shared_ptr B new B std vector boost any vec a 1 a2 b1 b2 std for_each vec. end foo std cout n std cout any s bl and b2 have been destroyed which means n that the shared_ptrs reference counts became zero n When this program is run it produces the following output. Example of any and shared_ptr This any contained a boost shared_ptr A A is_virtual A not_virtual The any didn t contain anything that concerns this function This any contained a boost shared_ptr A B is_virtual A not_virtual This any contained a boost shared_ptr B B is_virtual B not_virtual A A A A First we see that the any passed to foo contains a shared_ptr A which also happens to own an instance of A. The output is what one would expect. Next the any

Đã 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.