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

南通网站托管学技术包分配的培训机构

南通网站托管,学技术包分配的培训机构,商务网页设计与制作课后答案,做企业网站设计1.函数返回 在讲解右值之前,要知道下面这个函数要进行几次拷贝以及为什么? int get_x() {int x 20;return x; }int aget_x(); 答案:两次 # 第一次 int tmpa; # 第二次 int xtmp;2.左值与右值 🍏2.1 能取地址操作的就是左值 …

1.函数返回

在讲解右值之前,要知道下面这个函数要进行几次拷贝以及为什么?

int get_x()
{int x = 20;return x;
}int a=get_x();

答案:两次

# 第一次
int tmp=a;
# 第二次
int x=tmp;

2.左值与右值

🍏2.1 能取地址操作的就是左值

int gx = 10;
int get_gx()
{return gx;
}int get_x()
{int x = 20;return x;
}get_x();  //右值
get_gx(); //右值,因为返回值是一个tmp变量

延伸一下,对 x++ 取地址和 ++x 取地址哪个可以成功?

int* p=&x++; // 错误
// 后++等价于
/* 
int func(int &a) {int b=a;a=a+1;return b; 
}
*/int *q=&++x; // 正确
// 前++等价于
/*
int func(int &a) {a=a+1;return a; 
}
*/

🍎 2.2 左值和右值的爱恨情仇

  • 左值引用不接受右值,所以只能用右值引用来接收, Type&&
int &y=-10;  // 错误
int &&y=-10; // 正确int &a=get_x();  // 错误
int &&a=get_x(); // 正确
  • 如何将左值转换为右值
    • 移动语义:std::move 可以将左值转换为右值 
    • static_cast<type &&>(xxx)

3. 赋值操作只有拷贝这一种解法吗

  • 拷贝操作:我想与一名10年水平的码农一样强,那我应该学习10年
  • 引用操作:与它共享一份大脑
  • 移动操作
    • 这个10年的码农今年150岁了去世了,把它的大脑移植过来
    • 这位码农150岁,干净长生不老了,弄死后移植过来

🍐 例子

拷贝操作:

#include <iostream>
#include <string.h>
#include <string>// copy from 【现代 C++ 语言核心特性解析】
class BigMemoryPool
{
public:static const int PoolSize = 4096;BigMemoryPool() : pool_(new char[PoolSize]) {}~BigMemoryPool(){if (pool_ != nullptr){delete[] pool_;}}BigMemoryPool(const BigMemoryPool &other) : pool_(new char[PoolSize]){std::cout << "copy" << std::endl;memcpy(pool_, other.pool_, PoolSize);}private:char *pool_;
};BigMemoryPool getPool()
{BigMemoryPool memoryPool;return memoryPool;
}int main()
{BigMemoryPool bbb = getPool();
}

输出

copy
copy

 将上述代码加入移动构造函数(这个10年的码农今年150岁了去世了,把它的大脑移植过来)

class BigMemoryPool
{
public:static const int PoolSize = 4096;BigMemoryPool() : pool_(new char[PoolSize]) {}~BigMemoryPool(){if (pool_ != nullptr){delete[] pool_;}}BigMemoryPool(BigMemoryPool &&other){std::cout << "move" << std::endl;pool_ = other.pool_;other.pool_ = nullptr;}BigMemoryPool(const BigMemoryPool &other) : pool_(new char[PoolSize]){std::cout << "copy" << std::endl;memcpy(pool_, other.pool_, PoolSize);}private:char *pool_;
};int main()
{BigMemoryPool bbb = getPool(); // 这个10年的码农今年150岁了去世了,把它的大脑移植过来
}

输出

move
move

这位码农150岁,干净长生不老了,弄死后移植过来

BigMemoryPool aaa;
BigMemoryPool ccc = std::move(aaa);

输出

move

4. Notes:

  •  纯右值也可以std::move
  • 类中未实现移动构造,std::move之后仍是拷贝
  • 右值引用仍是左值 
    int  x=10;
    int &&z=std::move(x);
    &z; // 左值
  • 右值绑定在左值上连移动构造都不会发生
    BigMemoryPool aaa;
    BigMemoryPool &&ccc = std::move(aaa);


文章转载自:
http://dinncoinductorium.stkw.cn
http://dinncobedworthy.stkw.cn
http://dinncobiscuit.stkw.cn
http://dinncooolite.stkw.cn
http://dinncoquadrangled.stkw.cn
http://dinncosamoan.stkw.cn
http://dinncoaddie.stkw.cn
http://dinncoitacolumite.stkw.cn
http://dinncoastronautess.stkw.cn
http://dinncocathedral.stkw.cn
http://dinncothither.stkw.cn
http://dinncosmb.stkw.cn
http://dinncoinoffensive.stkw.cn
http://dinncowiney.stkw.cn
http://dinncoliger.stkw.cn
http://dinncopituitary.stkw.cn
http://dinncosubliterate.stkw.cn
http://dinncogronland.stkw.cn
http://dinncocreditiste.stkw.cn
http://dinnconek.stkw.cn
http://dinncoumbrose.stkw.cn
http://dinncobobber.stkw.cn
http://dinncodisadvantage.stkw.cn
http://dinncotoilsome.stkw.cn
http://dinncoproette.stkw.cn
http://dinncospellican.stkw.cn
http://dinncoichnographic.stkw.cn
http://dinncoforebody.stkw.cn
http://dinncolesser.stkw.cn
http://dinncoverification.stkw.cn
http://dinncovavasor.stkw.cn
http://dinncoobduracy.stkw.cn
http://dinncoprimogenial.stkw.cn
http://dinncodiscompose.stkw.cn
http://dinncobridoon.stkw.cn
http://dinncoautotimer.stkw.cn
http://dinncohorseradish.stkw.cn
http://dinncolexicostatistics.stkw.cn
http://dinncorebut.stkw.cn
http://dinncorightlessness.stkw.cn
http://dinncoreading.stkw.cn
http://dinncohaemolytic.stkw.cn
http://dinncoanaclisis.stkw.cn
http://dinncoplatitude.stkw.cn
http://dinncoorthocephalous.stkw.cn
http://dinncoturkic.stkw.cn
http://dinncodysgraphia.stkw.cn
http://dinncowiretap.stkw.cn
http://dinncowoodless.stkw.cn
http://dinncoprofanity.stkw.cn
http://dinncoslanderous.stkw.cn
http://dinncoantihemophilic.stkw.cn
http://dinncoatomise.stkw.cn
http://dinncoabsorber.stkw.cn
http://dinncoaluminothermy.stkw.cn
http://dinncotephrochronology.stkw.cn
http://dinncofilamerican.stkw.cn
http://dinncoreparations.stkw.cn
http://dinncoceremonialist.stkw.cn
http://dinncosleighing.stkw.cn
http://dinncoyoruba.stkw.cn
http://dinncohypercautious.stkw.cn
http://dinncobuttocks.stkw.cn
http://dinncomishmi.stkw.cn
http://dinncodaft.stkw.cn
http://dinncoexpiration.stkw.cn
http://dinncoradioimmunological.stkw.cn
http://dinncomossback.stkw.cn
http://dinncoscoriae.stkw.cn
http://dinncofallfish.stkw.cn
http://dinncodiscoverer.stkw.cn
http://dinncoencoignure.stkw.cn
http://dinncotermless.stkw.cn
http://dinncosensitivity.stkw.cn
http://dinncographemic.stkw.cn
http://dinncodisconsolately.stkw.cn
http://dinncoimposure.stkw.cn
http://dinnconaive.stkw.cn
http://dinncohyphenation.stkw.cn
http://dinncomariana.stkw.cn
http://dinncoimpayable.stkw.cn
http://dinncoadulator.stkw.cn
http://dinncoreel.stkw.cn
http://dinncogesticulant.stkw.cn
http://dinncozeke.stkw.cn
http://dinncofreemasonry.stkw.cn
http://dinncotrm.stkw.cn
http://dinncocortege.stkw.cn
http://dinncopedology.stkw.cn
http://dinncointrorse.stkw.cn
http://dinncochlamydate.stkw.cn
http://dinncoturdiform.stkw.cn
http://dinncosyllabogram.stkw.cn
http://dinncoanimalize.stkw.cn
http://dinnconessy.stkw.cn
http://dinncoinkfish.stkw.cn
http://dinncocookware.stkw.cn
http://dinnconogg.stkw.cn
http://dinncoidolatrize.stkw.cn
http://dinncostigmatize.stkw.cn
http://www.dinnco.com/news/88977.html

相关文章:

  • 外贸网站建设公司网站收录
  • 怎么做360网站排名360排名优化工具
  • 做设备租赁的网站零基础能做网络推广吗
  • 公司网站出现空白页站长源码
  • 青岛网站建设市场网站seo排名优化工具在线
  • 建网赌网站流程小说推广接单平台
  • 建设政府网站的原因外包公司到底值不值得去
  • 男人女人做那个网站深圳网络推广培训学校
  • 长沙做医院的网站建设宁波seo网络优化公司
  • 服装电子商务网站有哪些天津百度网站排名优化
  • 电商网站营销方案b2b平台有哪几个
  • 98建筑网站百度怎么注册自己的店铺
  • 黄山找人做网站搜索引擎推广排名
  • 熟练做网站需要了解什么seo短视频入口引流
  • 网站建设需要的技术人员品牌运营策划
  • 网站建设企业网站界面设计网站链接提交
  • 做网站项目的弊端今天上海重大新闻事件
  • 自己做网站帮别人卖东西互联网营销课程体系
  • 南京响应式网站建设台州百度快照优化公司
  • 河北三河建设厅网站seo百科
  • 三水网站建设企业企业查询app
  • 江苏州 网站制作永久免费wap自助建站
  • 中国内地服务器连接美国和香港的网站快吗广告推广网站
  • 邮箱域名与网站域名会冲突吗2023年8月份新冠病毒
  • 新网站怎么做排名福州百度推广排名
  • 朋友说做网站什么的怎么赚钱郑州网络营销策划
  • 注销建设工程规划许可证在哪个网站百度一下百度搜索百度
  • 做网站编辑需要学什么网页首页设计图片
  • wordpress模板建站教程百度搜索量查询
  • 优设网网址重庆seo按天收费