zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    tap事件的原理详解
    获取地理位置
    获取高度
    JSON字符串与JSON对象的区别
    zepto方法
    javascript 中 click 和onclick有什么区别呢
    oninput,onpropertychange,onchange的用法和区别
    js实时监听input中值得变化
    sql lock
    数据库SQL优化大总结
  • 原文地址:https://www.cnblogs.com/lanjianhappy/p/6082092.html
Copyright © 2011-2022 走看看