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,自动存储变量值未初始化值是未确定
     *
     */
    

      

  • 相关阅读:
    Java实现 蓝桥杯 历届试题 翻硬币
    后台管理UI推荐
    js跳转页面方法(转)
    Request常用方法 (总结)
    Eclipse项目 迁移到 Intellj IDEA
    由后端来类比前端设计的思考(转)
    数据库字段命名及设计规范(转)
    如何改变Myeclipse编辑区背景色(转)
    Myeclipse和windows调节成护眼色
    qt截获html请求(继承QNetworkAccessManager和QNetworkReply)
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/8017464.html
Copyright © 2011-2022 走看看