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

698元网站建设常用设计资源网站

698元网站建设,常用设计资源网站,深圳做网站哪家便宜,綦江建设银行网站临时对象的产生 临时对象也叫做 无名对象#xff0c;(使用pass by value的方式会引发copy的操作#xff0c;于是产生一个临时的对象)#xff0c;造成效率的负担#xff0c;但是可以可以制造一些临时对象在型别的后面 直接加上() 并可以指定初始数值#xff0c;相当于调用…临时对象的产生 临时对象也叫做 无名对象(使用pass by value的方式会引发copy的操作于是产生一个临时的对象)造成效率的负担但是可以可以制造一些临时对象在型别的后面 直接加上() 并可以指定初始数值相当于调用型别的构造函数但是不指定对象的名称临时对象一般常用于 仿函数和算法搭配上代码如下所示  printint的临时对象被传入 for_each函数中起作用当for_each结束的时候临时对象结束了他的生命 #include vector #include iostream #include algorithmtemplatetypename T class print{ public:void operator()(const Telem){ //operator 重载()std::cout elem ;} };void print_function(int value){std::cout value ; }int main(){int ia[6] {0,1,2,3,4,5};std::vectorintiv{ia,ia6};std::for_each(iv.begin(),iv.end(),printint()); //使用模板类的方式 // std::for_each(iv.begin(),iv.end(), print_function);} 静态常量整数成员在class内部 直接初始化 #include vector #include iostream #include algorithmtemplatetypename T class print{ public:void operator()(const Telem){ //operator 重载()std::cout elem ;} };void print_function(int value){std::cout value ; }template typename T class testClass{ public:static const T static_const_data_i 5;static T static_data_i; };//对于模板中使用static变量初始化这段代码不能省略 templatetypename T T testClassT::static_data_i 0;int main(){testClassinttemp;temp.static_data_i 9;std::cout testClassint::static_data_i std::endl;std::cout testClassint::static_const_data_i std::endl; } 递增/递减/解除引用 的运算符重载写法 #include vector #include iostream #include algorithmclass INT{friend std::ostream operator (std::ostream os,const INT i); public:INT(int i):m_i(i){};//prefix:increment and then fetchINT operator(){(this-m_i); //随着class的不同这一行有不同的操作return *this;}const INT operator(int){INT temp *this;(*this);return temp;}INT operator--(){--(this-m_i);return *this;}const INT operator--(int){INT temp *this;--(*this);return temp;}int operator*() const{return (int )m_i;} private:int m_i; };std::ostream operator(std::ostream os,const INT i){os [ i.m_i ] ;return os; }int main(){INT I(5);std::cout I ;// [5]std::cout I; // [7]std::cout I--; // [7]std::cout --I; // [5]std::cout *I; // 5 } 前闭后开 区间表示法 STL算法需要使用一对迭代器(泛型指针)表示 区间也就是操作的的范围使用[first.,last来表示实际的范围是first 开始 到 last-1结束 last指代的是 最后一个元素的下一个位置 使用的是 偏移一格 的标示法 templateclass InputIterator,class T InputIterator find(InputIterator first,InputIterator last,const T value){while(first ! last *first ! value){first;}return value; }templateclass InputIterator,class Function Function for_each(InputIterator first,InputIterator last,Function f){for (; first ! last; first) {f(*first);}return f; } 函数回调 操作符( function call) 函数调用操作(也就是左括号和右括号)  也可以被重载STL算法 提供了两个版本一个用于一般情况(比如按照递增序列进行排序)  一个用于特殊情况(按照用户指定的规则进行排序)用户指定的规则 是通过函数进行制定的先前 C语言时代 如果想将函数作为参数进行传递  只能使用函数指针的方式 #include vector #include iostream #include algorithmint fcmp(const void* elem1,const void* elem2){const int* i1 (const int*) elem1;const int* i2 (const int*) elem2;if (*i1 *i2){return -1;}else if(*i1 *i2){return 0;}elsereturn 1;}int main(){int ia[10] {32,92,67,58,10,4,25,52,59,54};for (int i 0; i 10; i) {std::cout ia[i] ;}qsort(ia,sizeof(ia)/sizeof (int), sizeof (int),fcmp);std::cout std::endl;for (int i 0; i 10; i) {std::cout ia[i] ;} } 函数指针有缺陷 无法维持自己的状态  也无法达到组件技术中的 可适配性也就是无法再将 某些装饰条件 加诸其上而改变其状态因此STL使用仿函数的形式实现了所谓的策略仿函数类似于函数比如针对某个类的进行operator()重载 就成为了仿函数如果需要将其转换为可配接的仿函数需要额外的努力这个例子 缺乏 可配接能力 的体现  将在第8章 详述 #include vector #include iostream #include algorithm//由于将operator()重载了 因此plus成为了一个仿函数 template class T struct plus{T operator()(const T x,const T y)const{return xy;} };//由于将operator()重载了 因此minus成为了一个仿函数 template class T struct minus{T operator()(const T x,const T y)const{return x-y;} };int main(){//产生仿函数对象plusintplus_obj;minusintminus_obj;//以下使用仿函数就像使用一般函数一样std::cout plus_obj(3,67) std::endl;std::cout minus_obj(67,3) std::endl;//以下直接产生函数的临时对象(第一对小括号) 并进行调用(第二队小括号)//使用括号产生临时对象std::cout plusint()(3,67) std::endl;std::cout minusint()(67,3) std::endl; } 参考链接 c类模板遇上static关键字_宿罪的博客-CSDN博客_static 模板c中ostream类的超详细说明 - 知乎
http://www.pierceye.com/news/769944/

相关文章:

  • 网站制作图书网站建设指南
  • 网站备案简单吗优化关键词排名软件
  • 泉山网站开发安徽建设工程造价信息网
  • 如何使用电子商务网站做seo需要用到什么软件
  • 新乡商城网站建设哪家专业潮汕学院网站开发
  • 西安响应式网站开发网站空间多少钱一年
  • 做电子相册的大网站怎样提高网站的权重
  • seo网站设计外包去哪个网站有客户找做标书的
  • 微商招商网站源码互联网营销推广方案
  • 深圳做网站服务公司河北石家庄最新新闻
  • 山东济南seo整站优化唐山网站建设那家性价比高
  • c 可以做哪些网站小说网站建设采集
  • 公司网站备案条件高校网站集群平台子站开发
  • 制作网站能赚钱吗单位发购物或电影卡有哪些app
  • 我们网站在那里登陆后台系统管理网站建设服务咨询
  • 免费上传图片的网址网站seo工作内容
  • chatgpt 网站一对一直播软件开发
  • 网站做排行多少费用个人电脑做网站打不开数据库
  • 做网站是比特币的滁州做网站电话号码
  • php网站开发说明怎么样建网站卖东西
  • 网站图片做多大浙江建设人才网
  • 网站关键词宝塔wordpress腾讯云
  • 优化排名推广教程网站免费房地产网站模板
  • 商城网站建设都需要多少钱电子商务网站建设预算
  • 万荣做网站怎么优化一个网站关键词
  • 潍坊市建设局网站网络工程师 网站建设
  • 做网站要求什么条件计算机网络技术学什么
  • 建设网站呼叫中心有什么好处中国能源建设集团有限公司级别
  • 免费论坛建站二 网站建设的重要性
  • wordpress站点迁移怎样做带音乐的表白网站