1:右值引用的定义:

类型 && i=被引用的对象;

    左值与右值的区别在于,右值是临时变量,例如,函数的返回值,并且无法被改变。

    当右值引用被初始化后,临时变量消失。

代码如下:

// 5.17.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>

int get()
{
    int i =4;

    return i;
}
int main()
{
    int &&k =get()+4;
    // int &i = get()+4;  //出错
    k++;
    std::cout<<"k的值"<<k<<std::endl;
    return 0;
}
View Code

相关文章:

  • 2021-08-29
  • 2022-12-23
  • 2021-12-29
  • 2021-10-29
  • 2021-04-16
  • 2021-06-23
猜你喜欢
  • 2021-10-12
  • 2021-09-05
  • 2022-02-12
  • 2022-12-23
  • 2022-02-20
  • 2021-05-16
相关资源
相似解决方案