namespace na { int i = 5; } namespace nb { int i = 10; } using namespace na; void main() { using namespace nb; i = 20; //这行报错 } 我知道将using namespace nb;改成用using nb::i;就不会报错 但我想问的是:如果不用using nb::i;这种声明的方式,就只用using namespace指示符,有没有什么方法处理这个变量冲突问题?
EXAMPLES
1.
To find all uses of the word "Posix" (in any case) in file text.mm and write with line numbers:
grep -i -n posix text.mm
2.
To find all empty lines in the standard input:
grep ^$
or:
grep -v .
3.
Both of the following commands print all lines containing strings "abc" or "def" or both:
grep -E 'abc|def'
grep -F 'abc
def'
4.
Both of the following commands print all lines matching exactly "abc" or "def" :
grep -E '^abc$|^def$'
grep -F -x 'abc
def'
using namespace *;(这里的*表示可以是任何命名空间)的作用是释放命名空间*中的变量或函数等,使之在被访问时可以不必加“命名空间::”,访问方法与一般的变量或函数无异
using namespace *;会给我们书写程序带来方便,但也要慎用,如果释放了多个命名空间中的东西后,它们又可能会引起命名冲突。