• c++命名空间using


     1 #include<iostream>
     2 
     3 namespace run1
     4 {
     5     int x = 10;
     6 }
     7 namespace run2
     8 {
     9     int x = 10;
    10 
    11     void show()
    12     {
    13         std::cout << x << std::endl;
    14     }
    15 }
    16 void run()
    17 {
    18 
    19     using namespace std;//等同局部变量
    20     using namespace run1;
    21     using namespace run2;//发生
    22     //cout << "hello world"<<x;
    23 }
    24 
    25 void main()
    26 {
    27     std::cout << "hello doubo";
    28     using  run2::x;
    29     using  run2::show;//单独引用命名空间变量或者函数
    30     std::cout << x << std::endl;
    31     show();
    32     std::cin.get();
    33 
    34 }
     1 #include<iostream>
     2 
     3 //using,可以省略std,
     4 //制定命名空间,
     5 //原则禁止using namespace std;//明确空间
     6 
     7 namespace  stdrun
     8 {
     9     int num = 101;
    10     void show()
    11     {
    12         std::cout << num << std::endl;
    13     }
    14 }
    15 namespace bobo = stdrun;//给自定义的别名
    16 
    17 
    18 namespace doubo = std;//给标准别名,不推荐
    19 //CPP编译器设置,禁止改变标准
    20 
    21 
    22 void main()
    23 {
    24     bobo::show();
    25     doubo::cout << "hello";
    26     doubo::cin.get();
    27 }
  • 相关阅读:
    vim中自动添加文件的作者、时间信息、版本等
    linux shell ipaddress
    java ant学习
    ganglia rpm安装
    深入分析 Java 中的中文编码问题
    javaIO调优
    超强的vim设置
    linux中core文件的生成和配置
    C和C++ 语言动态内存分配
    Linux的常用命令
  • 原文地址:https://www.cnblogs.com/lanjianhappy/p/6082092.html
Copyright © 2020-2023  润新知