tailieunhanh - HandBooks Professional Java-C-Scrip-SQL part 43

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 43', 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ả | class derived_class public another_class template typename T void intrusive_ptr_add_ref T t t- add_ref template typename T void intrusive_ptr_release T t if t- release 0 t- call_before_destruction delete t Here we have implemented generic versions of intrusive_ptr_add_ref and intrusive_ptr_release. We must therefore remove the generic versions that we previously put in the global namespace and replace them with non-templated versions accepting a pointer to reference_counter as their argument. Or we could omit these functions from the global namespace altogether to avoid cluttering it. For the two classes my_namespace another_class and my_namespace derived_class the special version which calls a member function call_before_destruction on its arguments is called. Other types either have corresponding functions in the namespace where they are defined or use the version in the global namespace if it exists. Here s a short program to illustrate how this works int main boost intrusive_ptr my_namespace another_class p1 new my_namespace another_class boost intrusive_ptr A p2 new good_class boost intrusive_ptr my_namespace derived_class p3 new my_namespace derived_class First the intrusive_ptr pl is passed a new instance of my_namespace another_class. When resolving the call to intrusive_ptr_add_ref the compiler finds the version in my_namespace the namespace of the my_namespace another_class argument. Thus the generic function which is provided for types in that namespace is correctly invoked. This applies when finding intrusive_ptr_release too. Then the intrusive_ptr p2 is created and passed a pointer of type A the one we created earlier . That type resides in the global namespace so when the compiler tries to find the best match for the call to intrusive_ptr_add_ref it finds only one which is the version accepting an argument of type pointer to reference_counter you ll recall that we had to remove the generic version from the global namespace . Because A inherits .

TÀI LIỆU LIÊN QUAN
10    158    1
6    184    1
7    162    1
5    157    1
6    160    1
6    152    1
6    150    1
6    206    1
7    154    1