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

      

  • 相关阅读:
    D-Bus,kdbus和Binder
    Android init system replaced with systemd & binder replaced by kdbus
    在 Android 上 chroot 一个 ArchLinux
    An experiment in porting the Android init system to GNU/Linux
    Android init
    Linux和RISC-V基金会宣合作,打造开源CPU!
    How does systemd use /etc/init.d scripts?
    SysV, Upstart and systemd init script coexistence
    Purism Shows Off Latest GNOME Mobile Shell Mockups For The Librem 5
    One Widget to Adapt Them All and to The Librem 5 Port Them
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/8017464.html
Copyright © 2020-2023  润新知