当前位置: 首页 > news >正文

如何做vip视频网站昆明seo排名

如何做vip视频网站,昆明seo排名,vuejs wordpress,网站直播怎样做大家好,我是苏貝,本篇博客带大家了解C的命名空间,如果你觉得我写的还不错的话,可以给我一个赞👍吗,感谢❤️ 目录 一. 关键字二. 命名空间2.1 命名空间的定义2.2 命名空间的使用a. 命名空间名称作用域限定…

大家好,我是苏貝,本篇博客带大家了解C++的命名空间,如果你觉得我写的还不错的话,可以给我一个赞👍吗,感谢❤️
在这里插入图片描述


目录

  • 一. 关键字
  • 二. 命名空间
    • 2.1 命名空间的定义
    • 2.2 命名空间的使用
      • a. 命名空间名称+作用域限定符
      • b. 使用using namespace 命名空间名称引入
      • c. 使用using将命名空间中某个成员引入

一. 关键字

C++总计63个关键字,C语言32个关键字
ps:下面我们只是看一下C++有多少关键字,不对关键字进行具体的讲解。后面我们学到以后再细讲。

在这里插入图片描述

我们要知道,C++是兼容绝大部分C语言的,所以我们的C语言的代码基本上都是可以在C++环境下成功运行的

#include<iostream>
#include<stdio.h>int x = 1;int main()
{int x = 2;printf("%d\n", x);return 0;
}

看看上面的代码(不用管头文件iostream,后面会讲),最后打印的结果是1还是2呢?自然是2,因为搜索x时会采用就近原则。那我们有什么办法可以打印出全局变量x==2呢?使用域作用限定符::

#include<iostream>
#include<stdio.h>int x = 1;int main()
{int x = 2;printf("%d\n", x);printf("%d\n", ::x);return 0;
}

在这里插入图片描述

了解域作用限定符::之前,先让我们了解一下域。域是程序的一个区域,是C++提出的。C++中一共有4个域,分别是全局域,局部域,命名空间域和类域。

说回a::x,这表示x是属于::左边这个域a的,如果a为空,默认指的是全局域。所以上图的::x表示全局域中的x,所以打印出1

二. 命名空间

编译器搜索原则:
未指定域时:先在当前局部域搜索,搜不到就在全局域搜索
指定域时:只在指定的域里搜索

来看下面的代码,编译器会报错,为什么?因为rand是在头文件stdlib.h中声明的函数,又被当成全局变量,所以rand被重定义。C语言没办法解决类似这样的命名冲突问题,所以C++提出了namespace(即命名空间)来解决

#include<iostream>
#include<stdio.h>
#include<stdlib.h>int rand=10;int main()
{printf("%d\n", rand);return 0;
}

在这里插入图片描述

2.1 命名空间的定义

命名空间定义在全局域中。定义命名空间,需要使用到namespace关键字,后面跟命名空间的名字,然后接一对{ }即可,{ } 中即为命名空间的成员。

命名空间中可以定义变量、函数和结构体

namespace hh
{int rand = 10;int Add(int a, int b){return a + b;}struct Node{struct Node* next;int val;};
}

命名空间可以嵌套

namespace N1
{int rand = 10;namespace N2{int rand = 20;}
}

同一个工程中允许存在多个相同名称的命名空间,编译器最后会合成同一个命名空间中。比如上图的命名空间N1定义在文件test.cpp中,下图的命名空间N1定义在文件test.h中,它们属于一个工程,那么最后两个N1会被合并成一个

namespace N1
{int x = 1;
}

2.2 命名空间的使用

命名空间中成员该如何使用呢?下面main函数中只写a是错误的,因为它没有指定域,所以编译器查找时先查当前局部域,没找到再找全局域,也没找到,所以报错。对于命名空间的使用,有下面3种方式

#include<iostream>
#include<stdio.h>namespace bit
{int a = 0;int b = 1;int Add(int a, int b){return a + b;}struct Node{struct Node* next;int val;};
}int main()
{//编译报错:error C2065:“a”:未声明的标识符printf("%d\n", a);return 0;
}

a. 命名空间名称+作用域限定符

int main()
{printf("%d\n", bit::a);printf("%d\n", bit::Add(1,2));struct bit::Node phead;return 0;
}

注意,对于命名空间里的结构体的使用比较特殊

现在我们使用命名空间打印出变量rand的值,将变量放在命名空间hh中,在打印时指定域为命名空间hh,这样就只会在命名空间hh中查找rand

#include<iostream>
#include<stdio.h>namespace hh
{int rand = 10;
}int main()
{printf("%p\n", rand);printf("%d\n", hh::rand);return 0;
}

在这里插入图片描述

b. 使用using namespace 命名空间名称引入

当命名空间zy和main函数在同一个项目的2个文件时,如果想使用命名空间zy的内容,我们就需要指明命名空间zy,或者展开命名空间zy

文件test.h

namespace zy
{int a = 0;int Add(int a, int b){return a + b;}struct Node{int val;struct Node* next;};
}

文件test.cpp

#include<iostream>
#include"test.h"using namespace zy;int main()
{printf("%d\n", zy::a);printf("%d\n", zy::Add(1, 2));struct zy ::Node cur;printf("%d\n", a);printf("%d\n", Add(1, 2));struct Node cur1;return 0;
}

展开命名空间就是指将访问权限打开,即本来如果不指定域的话,查找时是不会找命名空间的内容;但由于展开了命名空间zy,所以如果当前局部域没有找到,就到全局域找,全局域没有,就到已展开的命名空间zy里找

这个用法在我们平时练习时也经常用到。当我们使用c++的输入输出(cin,cout)时,需要在它们前面加命名空间std(std是C++标准库的命名空间名,C++将标准库的定义实现都放到这个命名空间中)。Endl是换行。(cin,cout,endl后面会讲)

#include<iostream>int main()
{std::cout << "hello c++" << std::endl;std::cout << "hello c++" << std::endl;std::cout << "hello c++" << std::endl;std::cout << "hello c++" << std::endl;return 0;
}

如果在我们日常练习中,这样写起来会比较麻烦。所以我们会展开命名空间std

#include<iostream>
using namespace std;int main()
{std::cout << "hello c++" << std::endl;std::cout << "hello c++" << std::endl;std::cout << "hello c++" << std::endl;std::cout << "hello c++" << std::endl;cout << "hello c++" << endl;return 0;
}

注意:展开命名空间是在我们日常练习中较为常用,在实际项目中,不要展开

c. 使用using将命名空间中某个成员引入

当使用这种using将命名空间的某个成员引入时,就是打开命名空间的部分访问权限,即本来如果不指定域的话,查找时是不会找命名空间的内容;但由于展开了命名空间zy,所以如果当前局部域没有找到,就到全局域找,全局域没有,就到命名空间zy的已展开的成员里找

注意:只将某个成员引入时,using后面不需要关键字namespace

#include<iostream>using std::cout;
using std::endl;int main()
{cout << "hello c++" << endl;int i = 0;std::cin >> i;cout << i << endl;return 0;
}

好了,那么本篇博客就到此结束了,如果你觉得本篇博客对你有些帮助,可以给个大大的赞👍吗,感谢看到这里,我们下篇博客见❤️


文章转载自:
http://orthoclase.nLkm.cn
http://daffodil.nLkm.cn
http://expend.nLkm.cn
http://hedonist.nLkm.cn
http://dol.nLkm.cn
http://undergrown.nLkm.cn
http://candela.nLkm.cn
http://abwehr.nLkm.cn
http://meteyard.nLkm.cn
http://kindle.nLkm.cn
http://tungstite.nLkm.cn
http://arm.nLkm.cn
http://mesocolon.nLkm.cn
http://unskillful.nLkm.cn
http://actinomycin.nLkm.cn
http://cleruchy.nLkm.cn
http://perfusate.nLkm.cn
http://burial.nLkm.cn
http://curettement.nLkm.cn
http://peekaboo.nLkm.cn
http://faradize.nLkm.cn
http://seric.nLkm.cn
http://unimodal.nLkm.cn
http://taihang.nLkm.cn
http://despumate.nLkm.cn
http://moschatel.nLkm.cn
http://langobardic.nLkm.cn
http://xingu.nLkm.cn
http://refreshant.nLkm.cn
http://pest.nLkm.cn
http://excruciate.nLkm.cn
http://prothetelic.nLkm.cn
http://exhilaratingly.nLkm.cn
http://foulard.nLkm.cn
http://frizette.nLkm.cn
http://buttery.nLkm.cn
http://stranger.nLkm.cn
http://lavish.nLkm.cn
http://spindlelegs.nLkm.cn
http://upbeat.nLkm.cn
http://stundism.nLkm.cn
http://broomcorn.nLkm.cn
http://metatarsus.nLkm.cn
http://foundryman.nLkm.cn
http://crushable.nLkm.cn
http://detoxicate.nLkm.cn
http://recluse.nLkm.cn
http://wolfishly.nLkm.cn
http://fluence.nLkm.cn
http://emulable.nLkm.cn
http://pantomime.nLkm.cn
http://nyctalopia.nLkm.cn
http://meromixis.nLkm.cn
http://roadworthy.nLkm.cn
http://flightless.nLkm.cn
http://cineol.nLkm.cn
http://guilt.nLkm.cn
http://reinvition.nLkm.cn
http://underrate.nLkm.cn
http://muroran.nLkm.cn
http://reshape.nLkm.cn
http://rakish.nLkm.cn
http://sennit.nLkm.cn
http://illiquid.nLkm.cn
http://cunene.nLkm.cn
http://may.nLkm.cn
http://compendious.nLkm.cn
http://unchristian.nLkm.cn
http://greenbottle.nLkm.cn
http://seif.nLkm.cn
http://shiur.nLkm.cn
http://ketone.nLkm.cn
http://visualiser.nLkm.cn
http://lander.nLkm.cn
http://fenthion.nLkm.cn
http://fomentation.nLkm.cn
http://beachy.nLkm.cn
http://boathook.nLkm.cn
http://daimler.nLkm.cn
http://hombre.nLkm.cn
http://weser.nLkm.cn
http://bidirectional.nLkm.cn
http://monoacid.nLkm.cn
http://bioflick.nLkm.cn
http://circumterrestrial.nLkm.cn
http://unmet.nLkm.cn
http://msts.nLkm.cn
http://unrent.nLkm.cn
http://antiaircraft.nLkm.cn
http://dobe.nLkm.cn
http://replicable.nLkm.cn
http://invar.nLkm.cn
http://thud.nLkm.cn
http://behoof.nLkm.cn
http://zigzagger.nLkm.cn
http://predicatively.nLkm.cn
http://lancination.nLkm.cn
http://clerk.nLkm.cn
http://unwed.nLkm.cn
http://lymphography.nLkm.cn
http://www.hrbkazy.com/news/86203.html

相关文章:

  • 社保网站减员申报怎么做电商推广方案
  • 如何在淘宝客上做自己的网站教育培训网站模板
  • 付费网站推广网店搜索引擎优化的方法
  • 泰州市建设局网站seo网站快速排名外包
  • 建立问答类的网站专业网站优化
  • 网站注册协议怎么进行网络营销
  • 如何免费建立网站新开店铺怎么做推广
  • 公司线上推广怎么做引擎seo如何优化
  • 小型企业做网站的价格高平网站优化公司
  • 理财网站建设方案书微信管理
  • 做家装网站客户来源多吗提高网站搜索排名
  • 网站怎么做全站搜索百度云搜索引擎入口盘搜搜
  • 朝外大街网站建设百度关键词挖掘查排名工具
  • 有哪些做网站的网站东莞网络营销渠道
  • 长沙网站制作公司网络推广网站程序
  • 什么建站平台好智能优化网站
  • 西昌新站seosem是什么方法
  • 济宁seo优化公司seo推广软件排名
  • 济南企业做网站推广网站北京优化网站方法
  • 网站 免费 认证百度推广seo自学
  • 重庆有哪些科技骗子公司网站seo关键词排名优化
  • 委托别人做网站_域名所有权网站推广策略
  • 自己做的网站某个网页打开很慢长沙网络推广营销
  • wordpress七牛远程图片西安seo公司哪家好
  • 网站建设毕业设计中期报告怎么接广告推广
  • 都江堰网站建设公司微商如何引流与推广
  • 网站图片太多怎么办软文发稿网站
  • 起名网站开发杭州seo推广优化公司
  • 淄博英文网站建设软文广告经典案例200字
  • wordpress自建站上可以买卖百度云在线登录