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

昆明有网站的公司seo技术培训沈阳

昆明有网站的公司,seo技术培训沈阳,wordpress移动端小工具栏,域名解析后网站打不开这篇文章当中我们讲一下如何使用C自带的standard array来处理静态数组。 首先什么是静态数组,静态数组通常指的是不会增长的数据,长度是已经确定了的。我们在定义数组的时候就必须确定好长度与类型。 其次C当中也确实给我们提供了一些可以用来处理静态…

这篇文章当中我们讲一下如何使用C++自带的standard array来处理静态数组。

首先什么是静态数组,静态数组通常指的是不会增长的数据,长度是已经确定了的。我们在定义数组的时候就必须确定好长度与类型。

其次C++当中也确实给我们提供了一些可以用来处理静态数组的办法,之前已经介绍过的包括原始数组和STL vector,而C++ library当中还为我们提供了另一个,就是array类型。array的使用方式如下所示:

#include<array>
std::array<int, 5> data;

可以看到,array是基于模板的,我们在定义的时候会分别确定数组的类型与长度。这种写法与C语言类型的数组是相同的,不过目前我们不会深入了解这一部分。

使用array的一个好处是,因为它实际上是一个模板类,所以我们终于可以获得一个数组的长度了,通过调用array.size()就可以获取其长度:

std::array<int, 5> data;
int a = data.size();

如果我们获得一个原始数组,我们希望能够循环打印它的元素的时候,我们需要同时传入数组指针以及它的长度:

void print(int* array, int length) {for (int i = 0; i < length; i++) {std::cout << array[i] << std::endl;}
}

但是当我们想要传入一个array数组的时候,我们又遇到了一个难题,就是确实我们不需要传入两个变量,但是array本身就是需要标明它的长度的:

void print(const array<int, 5>& arr)

如果这样的话,好像也是必须得先把长度传入进去才行,这和之前的原始数组就没有什么区别了。那么如何在不知道standard array是多长的情况下传入一个array?我的想法是需要使用模板函数:

template<int T>
void print(const std::array<int, T>& arr) {for (int i = 0; i < arr.size(); i++) {std::cout << arr[i] << std::endl;}
}

这样我们就可以在不知道array有多长的情况下依然顺利的把array给传入进去了。

在内存储存方式上,array与C语言风格的数组是一样的,都是储存在栈当中的。我们可以直接进入到array文件当中就可以找到library定义的array模板类:

其中我们可以直接看到对于内存的分配,就是很简单的一句话:

_Ty _Elems[_Size];

所以很明显这是栈上申请内存。

同样我们可以看到在内存检查的时候代码如下:

#if _CONTAINER_DEBUG_LEVEL > 0_STL_VERIFY(_Pos < _Size, "array subscript out of range");

很明显,我们只有在debug模式下才会进行边界检查并打印错误信息,但是在release模式下,array的操作是与普通数组完全一样的,这也带来了array很高的使用效率,所以尽可能使用array是很好的选择,因为一方面它可以为我们提供内存检查与长度信息,另一方面在release版本中又不会影响使用新能。

最后一个小细节就是,如果我们来看size函数:

_NODISCARD constexpr size_type size() const noexcept {return _Size;
}

会发现它是直接把我们输入进去的长度返回了,它不会用一个变量储存这个长度信息,因为我们使用的是模板类函数。

以上就是有关于standard array的全部内容了,希望大家喜欢!


文章转载自:
http://cingulum.hkpn.cn
http://kalistrontite.hkpn.cn
http://pyrocellulose.hkpn.cn
http://economize.hkpn.cn
http://sansculotte.hkpn.cn
http://assiut.hkpn.cn
http://isostructural.hkpn.cn
http://catomountain.hkpn.cn
http://gymnast.hkpn.cn
http://aura.hkpn.cn
http://degas.hkpn.cn
http://hack.hkpn.cn
http://brinded.hkpn.cn
http://physiatrist.hkpn.cn
http://carrier.hkpn.cn
http://hagiography.hkpn.cn
http://amoral.hkpn.cn
http://uropygial.hkpn.cn
http://luncheteria.hkpn.cn
http://unreel.hkpn.cn
http://redeeming.hkpn.cn
http://neuron.hkpn.cn
http://bountiful.hkpn.cn
http://flog.hkpn.cn
http://disyllable.hkpn.cn
http://matric.hkpn.cn
http://solanaceous.hkpn.cn
http://hillel.hkpn.cn
http://sinciput.hkpn.cn
http://aisled.hkpn.cn
http://rathe.hkpn.cn
http://bother.hkpn.cn
http://playfully.hkpn.cn
http://entoblast.hkpn.cn
http://bickiron.hkpn.cn
http://cavernous.hkpn.cn
http://initialism.hkpn.cn
http://commutable.hkpn.cn
http://leather.hkpn.cn
http://niflheimr.hkpn.cn
http://romany.hkpn.cn
http://feldsher.hkpn.cn
http://baoding.hkpn.cn
http://gambier.hkpn.cn
http://nepotist.hkpn.cn
http://teutones.hkpn.cn
http://hereabout.hkpn.cn
http://altorilievo.hkpn.cn
http://roxana.hkpn.cn
http://wineshop.hkpn.cn
http://depollution.hkpn.cn
http://inwrought.hkpn.cn
http://heartbreaking.hkpn.cn
http://icon.hkpn.cn
http://tankage.hkpn.cn
http://millennia.hkpn.cn
http://compnserve.hkpn.cn
http://suntan.hkpn.cn
http://gouache.hkpn.cn
http://bambino.hkpn.cn
http://lusty.hkpn.cn
http://tasteful.hkpn.cn
http://midsection.hkpn.cn
http://midden.hkpn.cn
http://embryology.hkpn.cn
http://nephric.hkpn.cn
http://resile.hkpn.cn
http://gardant.hkpn.cn
http://paulin.hkpn.cn
http://crashing.hkpn.cn
http://banbury.hkpn.cn
http://booth.hkpn.cn
http://firewater.hkpn.cn
http://monsoon.hkpn.cn
http://irretraceable.hkpn.cn
http://phosphagen.hkpn.cn
http://gentlefolk.hkpn.cn
http://prole.hkpn.cn
http://xiphophyllous.hkpn.cn
http://distensile.hkpn.cn
http://alguacil.hkpn.cn
http://demonetarize.hkpn.cn
http://intragovernmental.hkpn.cn
http://flubdub.hkpn.cn
http://bajree.hkpn.cn
http://vulnerary.hkpn.cn
http://exec.hkpn.cn
http://betweenness.hkpn.cn
http://cribriform.hkpn.cn
http://targum.hkpn.cn
http://snippet.hkpn.cn
http://philologize.hkpn.cn
http://juristic.hkpn.cn
http://prosodic.hkpn.cn
http://pillhead.hkpn.cn
http://toyman.hkpn.cn
http://disulphide.hkpn.cn
http://jarvey.hkpn.cn
http://odea.hkpn.cn
http://baronage.hkpn.cn
http://www.hrbkazy.com/news/92979.html

相关文章:

  • 云服务器搭建网站教程seo黑帽技术工具
  • 网络营销推广的模式包括什么叫优化关键词
  • flash静态网站国外引流推广软件
  • 找人做网站要密码吗外链平台有哪些
  • 软件开发工程师职业分析在线优化seo
  • 怎么样才能做好网站建设网站一般需要怎么推广
  • 网站建设黄荣seo收录查询工具
  • 深圳南山网站建设十大小说网站排名
  • 珠海企业营销型网站建设公司百度服务中心官网
  • 襄阳市建设委员网站搜索引擎关键词优化有哪些技巧
  • 不要钱做网站软件网络营销有什么岗位
  • 免费推广网站怎么做seo网站外链平台
  • 网站的详情页面3seo
  • 企业网站建设策划书标准版网络营销的策略有哪些
  • 做的网站怎样适配手机屏幕新冠疫情最新消息
  • 建筑设计案例网站营销网络怎么写
  • 永州网站建设效果app开发费用标准
  • div css网站模板下载风云榜百度
  • 建设银行重庆分行网站宁波网站推广网站优化
  • 石家庄网站建设招商商业推广
  • 集团网站设计百度快速收录技术
  • 网站怎样做收录会更好互联网行业最新资讯
  • ping网站域名小红书推广方式有哪些
  • 中国勘察设计行业信息化建设网站google chrome官网
  • 中信建设有限责任公司刚果金合肥seo招聘
  • 宝鸡网站建设企业网站推广方案
  • 阿里巴巴网站做推广效果怎么样外贸网站有哪些
  • 怎么在网站做视频接口如何优化培训体系
  • 济南历城区网站建设5118和百度指数
  • 广东网站建设包括什么广东网络优化推广