C ++ Library Study Notes-namespace nested scope issues

Source: Internet
Author: User

Summary:

1.: Root namespace or anonymous space of the ant table

2. when I is used in: ant: I and: ant: blas: I, ant: detail: I, default call ant: detail: I

3. for calling the level-level namespace, add the corresponding namespace

4. Saved domain namespaces

5. Even if there are multiple namespaces with the same name, no error will be reported. It is called according to the most partial call principle. If the global variable is the same as the local variable name, local variables are preferentially called.

 


Code:

 

<SPAN style = "FONT-SIZE: 14px"> # include <stdlib. h ># include <iostream> namespace detail {const int I = 99;} namespace ant {namespace blas {const int I = 0;} // end blasconst int I = 3; namespace detail {const int I = 33; void test () {std: cout <"I:" <I <std: endl; // 33 std :: cout <": detail: I" <: detail: I <std: endl; // 99 std: cout <"detail :: I "<detail: I <std: endl; // 33 std: cout <": ant: blas: I: "<:: ant: blas: I <std: endl; // 0 std: cout <"ant: blas: I" <: ant :: blas: I <std: endl; // 0 std: cout <"blas: I" <blas: I <std: endl; // 0 level/std: cout <": blas: I" <: blas: I <std: endl; // error std:: cout <"ant: I" <ant: I <std: endl; // 3 }}// end detail} // end namespace antusing namespace std; int main () {ant: detail: test (); return 0 ;} </SPAN>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.