码迷,mamicode.com
首页 > 其他好文 > 详细

cpp_namespace

时间:2014-05-22 02:08:48      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:class   c   code   a   int   os   

using and using namespace have validity only in the same block in which they are stated or in the entire source code file if they are used directly in the global scope. For example, it would be possible to first use the objects of one namespace and then those of another one by splitting the code in different blocks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// using namespace example
#include <iostream>
using namespace std;

namespace first
{
  int x = 5;
}

namespace second
{
  double x = 3.1416;
}

int main () {
  {
    using namespace first;
    cout << x << ‘\n‘;
  }
  {
    using namespace second;
    cout << x << ‘\n‘;
  }
  return 0;
}

cpp_namespace,布布扣,bubuko.com

cpp_namespace

标签:class   c   code   a   int   os   

原文地址:http://www.cnblogs.com/hackerma/p/3738662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!