c++官方文档-命名空间
#include<stdio.h>
#include<iostream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <climits>
#include <sstream>
#include <cstdlib>
using namespace std; /**
* 命名空间
*
*namespace identifier
*{
* named_entities
*}
*/
namespace foo
{
int value()
{
return 5;
}
} namespace bar
{
const double pi = 3.1416;
double value()
{
return 2 * pi;
}
} namespace first
{
int x = 5;
int y = 10;
} namespace second
{
double x = 3.1416;
double y = 2.7183;
} //int main()
//{
// cout << foo::value() << '\n';
// cout << bar::value() << '\n';
// cout << bar::pi << '\n';
// using first::x;
// using second::y;
// cout << x << endl;
// cout << y << endl;
// cout << first::y << endl;
// cout << second::x << endl;
// return 0;
//}
int x;
int main()
{
//using namespace和using的作用域
/*
{
using namespace first;
cout << x << '\n';
}
{
using namespace second;
cout << x << '\n';
}
//命名空间别名namespace new_name = current_name;
*/
//静态存储和自动存储
int y;
cout << x << '\n';
cout << y << '\n';
return 0;
}
/**
*
* 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.
*
*But there is another substantial difference between variables with static storage and variables with automatic storage:
*- Variables with static storage (such as global variables) that are not explicitly initialized are automatically initialized to zeroes.
*- Variables with automatic storage (such as local variables) that are not explicitly initialized are left uninitialized, and thus have an undetermined value.
*
*全局变量和命名空间是静态存储,在程序运行期间一直存在,本地变量是自动存储类型,只存在块内.
*
*俩个的不同点,静态存储的变量未初始化则默认值是0,自动存储变量值未初始化值是未确定
*
*/
c++官方文档-命名空间的更多相关文章
- clang format 官方文档自定义参数介绍(中英文)
官方文档:http://clang.llvm.org/docs/ClangFormatStyleOptions.html 中文 在代码中配置样式 当使用 clang::format::reformat ...
- Spring JMS 官方文档学习
最后部分的XML懒得写了,因为个人更倾向于JavaConfig形式. 为知笔记版本见这里,带格式~ 做了一个小demo,放到码云上了,有兴趣的点我. 说明:需要先了解下JMS的基础知识. 1.介绍 S ...
- Spring 4 官方文档学习(十一)Web MVC 框架
介绍Spring Web MVC 框架 Spring Web MVC的特性 其他MVC实现的可插拔性 DispatcherServlet 在WebApplicationContext中的特殊的bean ...
- 【Docker官方文档】理解Docker
本文来自Docker的官方文档,详细介绍了Docker的体系结构.重要概念.内部工作机理等内容,推荐不了解Docker内部原理的同学阅读. 什么是Docker? Docker是一个用于开发.交付和运行 ...
- gRPC官方文档(概览)
文章来自gRPC 官方文档中文版 概览 开始 欢迎进入 gRPC 的开发文档,gRPC 一开始由 google 开发,是一款语言中立.平台中立.开源的远程过程调用(RPC)系统. 本文档通过快速概述和 ...
- 2017.4.10 spring-ldap官方文档学习
官网:http://www.springframework.org/ldap 官方文档及例子(重要):http://docs.spring.io/spring-ldap/docs/2.1.0.RELE ...
- Protocol Buffers官方文档(proto3语言指南)
本文是对官方文档的翻译,大部分内容都是引用其他一些作者的优质翻译使文章内容更加通俗易懂(自己是直译,读起来有点绕口难理解,本人英文水平有限),参考的文章链接在文章末尾 这篇指南描述如何使用protoc ...
- Hive官方文档
Hive官方文档 内容列表 Cloudera制作的Hive介绍视频 安装与配置 系统需求 安装Hive发行版 从Hive源码编译 运行Hive 配置管理概览 运行时配置 Hive, Map-R ...
- 20191127 Spring Boot官方文档学习(9.1-9.3)
9."使用方法"指南 9.1.Spring Boot应用程序 9.1.1.创建自己的FailureAnalyzer FailureAnalyzer被包装在FailureAnalys ...
随机推荐
- stm32 DMA配置
DMA就是将一个地址空间复制到另外一个地址空间.DMA传输方式无需CPU直接控制传输,也没有中断处理方式那样保留现场和恢复现场的过程,通过硬件为RAM与I/O设备直接传送数据,使CPU的效率大大的提高 ...
- HihoCoder - 1789:阶乘问题 (简单数学)
描述 给定 n, k,求一个最大的整数 m,使得 km 是 n! 的约数 输入 第一行两个正整数 n, k 2 ≤ n,k ≤ 109 输出 输出最大的 m 样例输入 5 2 样例输出 3 思路:我们 ...
- LG3812 【模板】线性基
题意 给定n个整数(数字可能重复),求在这些数中选取任意个,使得他们的异或和最大. \(1≤n≤50,0≤S_i≤2^{50}\) 分析 模板题. 推荐一篇好博客 现在我来证明一下线性基的性质. 性质 ...
- treeql 基于rest 标准的接口开发协议
treeql 可以让我们按照数据库的关系模型,生成一个tree 模型的json 数据,基于rest 标准, 从设计上,来说还是很不错的,但是从长远发展来说graphql 应该会更好,也有相关的比较 参 ...
- SocketIO4Net.Client
Project Description SocketIO4Net.Client Update as of 11/02/2013 A develop branch is up at https://gi ...
- log4net保存到数据库系列五、新增数据库字段
园子里面有很多关于log4net保存到数据库的帖子,但是要动手操作还是比较不易,从头开始学习log4net数据库日志一.WebConfig中配置log4net 一.WebConfig中配置log4ne ...
- php脚本输出js代码不执行的解决办法和原理。
<?phpecho "<script>alert('我弹出来了')</script>";?> 很简单你一句话就可以在PHP里面输出JS脚本让浏览 ...
- Oracle 基础知识入门
前记: 近来项目用到Oracle数据库,大学学了点,后面基本忘记得差不多了,虽然基本语法跟sql 差不多,但是oracle知识是非常多的. 这里简单说点基础知识,希望后面补上更多的关于ORacle知识 ...
- Mac OSX 正确地同时安装Python 2.7 和Python3
出处:http://www.jianshu.com/p/51811fa24752 python3 默认安装位置:/usr/local/Cellar/python3
- PHP 小技巧之__callStatic魔术方法使用
使用 PHP 框架时,经常会用到 ORM 模型查询数据库,有没有疑问:为啥有些 ORM 中的静态查询方法,不能通过函数追踪下去呢,很有可能就是使用了 __callStatic 魔术方法的小技巧 这里贴 ...