C Programming FAQs: Frequently Asked Questions

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 }

Категории