zoukankan      html  css  js  c++  java
  • 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() << '
    ';
    //	cout << bar::value() << '
    ';
    //	cout << bar::pi << '
    ';
    //	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 << '
    ';
    	}
    	{
    		using namespace second;
    		cout << x << '
    ';
    	}
    	//命名空间别名namespace new_name = current_name;
    */
    	//静态存储和自动存储
    	int y;
    	cout << x << '
    ';
    	cout << y << '
    ';
    	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,自动存储变量值未初始化值是未确定
     *
     */
    

      

  • 相关阅读:
    yafu安装使用方法以及mismatched parens解决方法
    Bubble Babble Binary Data Encoding的简介以及bubblepy的安装使用方法
    python-gzip解压缩(实验吧SOS)
    python用模块zlib压缩与解压字符串和文件的方法
    IDA-IDC脚本编写语法
    南邮CTF密码学,mixed_base64
    各种类型文件头标准编码
    实验吧,心中无码
    Vue + webpack的纯前端项目如何配置外部配置文件
    js小技巧
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/8017464.html
Copyright © 2011-2022 走看看