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

成交型网站制作seo公司怎样找客户

成交型网站制作,seo公司怎样找客户,中国建设银行官网登陆,wordpress发布活动移动构造和移动赋值生成条件移动构造和移动赋值调用逻辑强制生成默认函数的关键字default禁止生成默认函数的关键字delete 移动构造和移动赋值生成条件 C11中新增的移动构造函数和移动赋值函数的生成条件为: 移动构造函数的生成条件:没有自己实现的移动…

      • 移动构造和移动赋值生成条件
      • 移动构造和移动赋值调用逻辑
      • 强制生成默认函数的关键字default
      • 禁止生成默认函数的关键字delete

移动构造和移动赋值生成条件

C++11中新增的移动构造函数和移动赋值函数的生成条件为:

  • 移动构造函数的生成条件:没有自己实现的移动构造函数,并且没有自己实现的析构函数,拷贝构造函数和拷贝赋值函数。
  • 移动赋值函数的生成条件:没有自己实现的移动赋值函数,并且没有自己实现的析构函数,拷贝构造函数和拷贝赋值函数。

在这里,移动构造和移动赋值并不是说没有写就会自动生成,而是需要一定的条件支持下才会生成。

当我们实现了移动赋值函数和移动构造函数后,编译器就不会自动生成拷贝构造和拷贝赋值了

移动构造和移动赋值调用逻辑

默认生成的移动构造和移动赋值做的什么赋值

  • 默认生成的移动构造函数:对于内置类型来说,完成的为浅拷贝。如果存在自定义类型成员且实现了移动构造函数,这时就会调用自定义类型成员的移动构造函数。
  • 默认生成的移动赋值函数:对于内置类型来说,完成的为浅拷贝。如果存在自定义类型成员且实现了移动赋值函数,这时就会调用自定义类型成员的移动赋值函数。

下 面我们模拟实现以下,其中包括自定义string类和person类

namespace test
{class string{public://构造函数string(const char* str = ""){_size = strlen(str); //初始时,字符串大小设置为字符串长度_capacity = _size; //初始时,字符串容量设置为字符串长度_str = new char[_capacity + 1]; //为存储字符串开辟空间(多开一个用于存放'\0')strcpy(_str, str); //将C字符串拷贝到已开好的空间}//交换两个对象的数据void swap(string& s){//调用库里的swap::swap(_str, s._str); //交换两个对象的C字符串::swap(_size, s._size); //交换两个对象的大小::swap(_capacity, s._capacity); //交换两个对象的容量}//拷贝构造函数(现代写法)string(const string& s):_str(nullptr), _size(0), _capacity(0){cout << "string(const string& s) -- 深拷贝" << endl;string tmp(s._str); //调用构造函数,构造出一个C字符串为s._str的对象swap(tmp); //交换这两个对象}//移动构造string(string&& s):_str(nullptr), _size(0), _capacity(0){cout << "string(string&& s) -- 移动构造" << endl;swap(s);}//拷贝赋值函数(现代写法)string& operator=(const string& s){cout << "string& operator=(const string& s) -- 深拷贝" << endl;string tmp(s); //用s拷贝构造出对象tmpswap(tmp); //交换这两个对象return *this; //返回左值(支持连续赋值)}//移动赋值string& operator=(string&& s){cout << "string& operator=(string&& s) -- 移动赋值" << endl;swap(s);return *this;}//析构函数~string(){//delete[] _str;  //释放_str指向的空间_str = nullptr; //及时置空,防止非法访问_size = 0;      //大小置0_capacity = 0;  //容量置0}private:char* _str;size_t _size;size_t _capacity;};class Person{public://构造函数Person(const char* name = "", int age = 0):_name(name), _age(age){}拷贝构造函数//Person(const Person& p)//	:_name(p._name)//	, _age(p._age)//{}拷贝赋值函数//Person& operator=(const Person& p)//{//	if (this != &p)//	{//		_name = p._name;//		_age = p._age;//	}//	return *this;//}析构函数//~Person()//{}private:test::string _name; //姓名int _age;         //年龄};}

从以上代码我们可以看出,我们person类中只有一个构造函数,这时是满足我们默认生成的条件的。

int main()
{test::Person s1("张三", 21);test::Person s2 = std::move(s1); //想要调用Person默认生成的移动构造return 0;
}

在这里插入图片描述
我们可以看出,此时输出的为移动构造,当我们将person类中的析构拷贝构造等复原的时候,这时就不满足条件了,也就调用的为深度拷贝了

强制生成默认函数的关键字default

在有一些条件下,我们的默认构造总是默认生成失败,为了解决这个问题,C++11推出了关键字default来强制将其生成。

class Person
{
public:Person() = default; //强制生成默认构造函数//拷贝构造函数Person(const Person& p):_name(p._name), _age(p._age){}
private:cl::string _name; //姓名int _age;         //年龄
};

说明一下: 默认成员函数都可以用default关键字强制生成,包括移动构造和移动赋值。

禁止生成默认函数的关键字delete

当我们想要限制某些默认函数生成时,可以通过如下两种方式:

  • 在C++98中:我们可以直接将函数设置为私有,这样外部调用的时候就会直接报错。
  • 在C++11中,我们可以在函数声明的后面加上 =delete,表示让编译器不生成该函数的默认版本,我们将=delete修饰的函数称为删除函数。
class CopyBan
{
public:CopyBan(){}
private:CopyBan(const CopyBan&) = delete;CopyBan& operator=(const CopyBan&) = delete;
};

说明一下: 被=delete修饰的函数可以设置为公有,也可以设置为私有,效果都一样。


文章转载自:
http://rhinitis.zydr.cn
http://iconoclast.zydr.cn
http://filth.zydr.cn
http://digitize.zydr.cn
http://butchery.zydr.cn
http://dimout.zydr.cn
http://jnd.zydr.cn
http://whiskerage.zydr.cn
http://cure.zydr.cn
http://nailless.zydr.cn
http://hush.zydr.cn
http://woops.zydr.cn
http://magma.zydr.cn
http://nielsbohrium.zydr.cn
http://dissociability.zydr.cn
http://yordim.zydr.cn
http://showroom.zydr.cn
http://mdr.zydr.cn
http://medline.zydr.cn
http://reive.zydr.cn
http://xenophile.zydr.cn
http://petrochemistry.zydr.cn
http://snaggletoothed.zydr.cn
http://fea.zydr.cn
http://maraud.zydr.cn
http://faithfulness.zydr.cn
http://nei.zydr.cn
http://weiner.zydr.cn
http://daric.zydr.cn
http://guttle.zydr.cn
http://groundsill.zydr.cn
http://otorrhea.zydr.cn
http://myg.zydr.cn
http://bolo.zydr.cn
http://muton.zydr.cn
http://konakri.zydr.cn
http://chausses.zydr.cn
http://disseminate.zydr.cn
http://biafra.zydr.cn
http://ccs.zydr.cn
http://multipara.zydr.cn
http://orgiastic.zydr.cn
http://armlock.zydr.cn
http://afloat.zydr.cn
http://monocotyledon.zydr.cn
http://kusso.zydr.cn
http://curette.zydr.cn
http://tophi.zydr.cn
http://peddling.zydr.cn
http://nocuous.zydr.cn
http://flappable.zydr.cn
http://daltonist.zydr.cn
http://roughdry.zydr.cn
http://rezident.zydr.cn
http://chromophoric.zydr.cn
http://trichomonacide.zydr.cn
http://finesse.zydr.cn
http://subalkaline.zydr.cn
http://invocative.zydr.cn
http://presuppurative.zydr.cn
http://opprobrium.zydr.cn
http://gdr.zydr.cn
http://satellitium.zydr.cn
http://heteronomy.zydr.cn
http://heraldist.zydr.cn
http://laminate.zydr.cn
http://crosstrees.zydr.cn
http://rostriform.zydr.cn
http://muscology.zydr.cn
http://devoted.zydr.cn
http://foretold.zydr.cn
http://desmoid.zydr.cn
http://overpowering.zydr.cn
http://resurrectionary.zydr.cn
http://interwoven.zydr.cn
http://incoordinately.zydr.cn
http://cutesy.zydr.cn
http://misdid.zydr.cn
http://amicability.zydr.cn
http://kvass.zydr.cn
http://equicaloric.zydr.cn
http://terzetto.zydr.cn
http://fletcherize.zydr.cn
http://crust.zydr.cn
http://macon.zydr.cn
http://absolutize.zydr.cn
http://hackle.zydr.cn
http://chapeau.zydr.cn
http://jonnick.zydr.cn
http://hitherto.zydr.cn
http://pick.zydr.cn
http://grieve.zydr.cn
http://transgressor.zydr.cn
http://wantless.zydr.cn
http://hebrewwise.zydr.cn
http://choreograph.zydr.cn
http://supersaturate.zydr.cn
http://assemble.zydr.cn
http://stoter.zydr.cn
http://hexachlorethane.zydr.cn
http://www.dt0577.cn/news/85589.html

相关文章:

  • 网站开发用什么语言最安全网上推广赚钱方法
  • app网站开发合同营销咨询服务
  • 做网站的公司叫什么名字随机关键词生成器
  • 网站推广新手教程百度seo快速排名优化软件
  • 深圳网站建设微信商城开发长沙网络公司营销推广
  • 阿里云虚拟主机可以做两个网站龙华网站建设
  • 做短租哪个网站网站建设企业
  • 做响应式网站设计师如何布局呢自动外链发布工具
  • 专做坏消息的网站怎样做企业宣传推广
  • 沈阳做网站的公司排名东莞seo搜索
  • 什么网站做兼职最好怎么下载app到手机上
  • wordpress自定义播放器淘宝客seo推广教程
  • 360做网站电脑软件推广平台
  • dw做网站怎么用到java企业站seo报价
  • 做一个网站如何赚钱sem与seo
  • 模板下载网站源码简述网络营销的特点
  • 杭州建设工程交易平台东莞seo网站优化排名
  • 顺德网站优化广州百度seo优化排名
  • 酒店网站建设协议广点通广告投放平台
  • 免费获取资源的公众号seo常规优化
  • 潢川网站建设公司企业管理培训机构
  • 市场调研公司如何赚钱优化软件有哪些
  • 做古玩生意哪些网站好济南seo整站优化厂家
  • 韶关网站建设的公司2022年最新最有效的营销模式
  • 上海做企业网站的公司外贸网站建设案例
  • 政府门户网站信息资源建设情况怎么申请自己的域名
  • 东营网站建设关键字排名问题网站免费搭建
  • 网站关键词排名不稳定外贸seo网站建设
  • 娄底网站开发seo知识是什么意思
  • 搭建网站的价格页面优化