FAQ 15.05 What are some of the rules for using namespaces?

graphics/new_icon.gif

The following example due to Stroustrup (C++ Programming Language, Third Edition, 1997) illustrates some of the basic ideas.

 namespace X {   int i, j, k; } int k; void f1() throw() {   int i = 0;   using namespace X;  // make names from X accessible   i++;                // local i   j++;                // X::j   k++;                // error: X::k or global k?   ::k++;              // the global k   X::k++;             // X's k } void f2() throw() {   int i = 0;   using X::i;         // Error: i declared twice in f2()   using X::j;   using X::k;         // Hides global k   i++;   j++;                // X::j   k++;                // X::k } 


C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net