1. #include<stdio.h>
  2. #include<iostream>
  3. #include<queue>
  4. #include<map>
  5. #include<memory.h>
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <algorithm>
  9. #include <climits>
  10. #include <sstream>
  11. #include <cstdlib>
  12. using namespace std;
  13.  
  14. /**
  15. * 命名空间
  16. *
  17. *namespace identifier
  18. *{
  19. * named_entities
  20. *}
  21. */
  22. namespace foo
  23. {
  24. int value()
  25. {
  26. return 5;
  27. }
  28. }
  29.  
  30. namespace bar
  31. {
  32. const double pi = 3.1416;
  33. double value()
  34. {
  35. return 2 * pi;
  36. }
  37. }
  38.  
  39. namespace first
  40. {
  41. int x = 5;
  42. int y = 10;
  43. }
  44.  
  45. namespace second
  46. {
  47. double x = 3.1416;
  48. double y = 2.7183;
  49. }
  50.  
  51. //int main()
  52. //{
  53. // cout << foo::value() << '\n';
  54. // cout << bar::value() << '\n';
  55. // cout << bar::pi << '\n';
  56. // using first::x;
  57. // using second::y;
  58. // cout << x << endl;
  59. // cout << y << endl;
  60. // cout << first::y << endl;
  61. // cout << second::x << endl;
  62. // return 0;
  63. //}
  64. int x;
  65. int main()
  66. {
  67. //using namespace和using的作用域
  68. /*
  69. {
  70. using namespace first;
  71. cout << x << '\n';
  72. }
  73. {
  74. using namespace second;
  75. cout << x << '\n';
  76. }
  77. //命名空间别名namespace new_name = current_name;
  78. */
  79. //静态存储和自动存储
  80. int y;
  81. cout << x << '\n';
  82. cout << y << '\n';
  83. return 0;
  84. }
  85. /**
  86. *
  87. * The storage for variables with global or namespace scope is allocated for the entire duration of the program. This is known as static storage, and it contrasts with the storage for local variables (those declared within a block). These use what is known as automatic storage. The storage for local variables is only available during the block in which they are declared; after that, that same storage may be used for a local variable of some other function, or used otherwise.
  88. *
  89. *But there is another substantial difference between variables with static storage and variables with automatic storage:
  90. *- Variables with static storage (such as global variables) that are not explicitly initialized are automatically initialized to zeroes.
  91. *- Variables with automatic storage (such as local variables) that are not explicitly initialized are left uninitialized, and thus have an undetermined value.
  92. *
  93. *全局变量和命名空间是静态存储,在程序运行期间一直存在,本地变量是自动存储类型,只存在块内.
  94. *
  95. *俩个的不同点,静态存储的变量未初始化则默认值是0,自动存储变量值未初始化值是未确定
  96. *
  97. */

  

c++官方文档-命名空间的更多相关文章

  1. clang format 官方文档自定义参数介绍(中英文)

    官方文档:http://clang.llvm.org/docs/ClangFormatStyleOptions.html 中文 在代码中配置样式 当使用 clang::format::reformat ...

  2. Spring JMS 官方文档学习

    最后部分的XML懒得写了,因为个人更倾向于JavaConfig形式. 为知笔记版本见这里,带格式~ 做了一个小demo,放到码云上了,有兴趣的点我. 说明:需要先了解下JMS的基础知识. 1.介绍 S ...

  3. Spring 4 官方文档学习(十一)Web MVC 框架

    介绍Spring Web MVC 框架 Spring Web MVC的特性 其他MVC实现的可插拔性 DispatcherServlet 在WebApplicationContext中的特殊的bean ...

  4. 【Docker官方文档】理解Docker

    本文来自Docker的官方文档,详细介绍了Docker的体系结构.重要概念.内部工作机理等内容,推荐不了解Docker内部原理的同学阅读. 什么是Docker? Docker是一个用于开发.交付和运行 ...

  5. gRPC官方文档(概览)

    文章来自gRPC 官方文档中文版 概览 开始 欢迎进入 gRPC 的开发文档,gRPC 一开始由 google 开发,是一款语言中立.平台中立.开源的远程过程调用(RPC)系统. 本文档通过快速概述和 ...

  6. 2017.4.10 spring-ldap官方文档学习

    官网:http://www.springframework.org/ldap 官方文档及例子(重要):http://docs.spring.io/spring-ldap/docs/2.1.0.RELE ...

  7. Protocol Buffers官方文档(proto3语言指南)

    本文是对官方文档的翻译,大部分内容都是引用其他一些作者的优质翻译使文章内容更加通俗易懂(自己是直译,读起来有点绕口难理解,本人英文水平有限),参考的文章链接在文章末尾 这篇指南描述如何使用protoc ...

  8. Hive官方文档

    Hive官方文档     内容列表 Cloudera制作的Hive介绍视频 安装与配置 系统需求 安装Hive发行版 从Hive源码编译 运行Hive 配置管理概览 运行时配置 Hive, Map-R ...

  9. 20191127 Spring Boot官方文档学习(9.1-9.3)

    9."使用方法"指南 9.1.Spring Boot应用程序 9.1.1.创建自己的FailureAnalyzer FailureAnalyzer被包装在FailureAnalys ...

随机推荐

  1. 在intent-filter中的配置

    1.scheme约束和mimetype的数据类型,这些都可以自己去定义. 2.但是由于在MainActivity却不能直接将这两个参数分开来写,例如setdata和settype,这样会互相删除. 因 ...

  2. HTML第二课——css

    请关注公众号:自动化测试实战 先给大家提个建议,就是用sublime编辑器来编写.用其他的也无所谓,我只是建议,因为这个会帮你自动补全很多代码. css概念 css叫层叠样式表.意思就是一层一层的叠加 ...

  3. MySQL--Delete语句别名+LIMIT

    在MySQL中,可以使用LIMIT来限制删除的数量,但部分写法并不支持LIMIT. LIMIT方式 对于查询: ; 可以转换成: ; 别名方式: ## 使用别名 DELETE T FROM T1 AS ...

  4. stenciljs 学习九 使用jsx

    可以使用jsx 方便组件的开发 基本格式 主要是render 函数 class MyComponent { render() { return ( <div> <h1>Hell ...

  5. centos7 添加用户并授权root权限

    centos7.2 版本,我们不可能每次都用root账号登陆,root账号公认的不安全,所以,首先,禁止掉root账号的登陆.1.静止root账号登陆. $ vi /etc/ssh/sshd.conf ...

  6. 关于 Cookie-free Domains (为什么将静态图片,js,css存放到单独的域名?)

    这篇文章对高性能web开发具有参考性:http://developer.yahoo.com/performance/rules.html 本文主要描述使用裸域名做网站主域名时,如何用子域名做 cook ...

  7. FineUI 修改config表属性

    此功能可用来设置系统的不同的标题 private void SelectSystem() { ConfigHelper.Title = DropDownList1.SelectedText; Conf ...

  8. WinForm下ComboBox设定SelectedValue总结 (SelectedValue==null解决办法)[转]

    http://www.cnblogs.com/qqflying/archive/2013/05/23/3096050.html 实践发现:以SelectedIndex赋值让ComboBox自动选中时能 ...

  9. 2017头条笔试题:二维点集中找出右上角没有点的点并按x坐标从小到大打印坐标

    PS:这篇是之前本来就想发的但是一直没时间写,加上今天做了京东的题,结果代码名就命名为jingdong了……懒得改代码名重新跑一遍结果了=.= 暴力法去做就是遍历每个点,判断它是不是“最大点”.判断过 ...

  10. 终于完成了 源码 编译lnmp环境

    经过了大概一个星期的努力,终于按照海生的编译流程将lnmp环境源码安装出来了 nginx 和php 主要参考 http://hessian.cn/p/1273.html mysql 主要参考 http ...