1 Star 0 Fork 115

alanlee / CPlusPlusThings

forked from ALONE_WORK / CPlusPlusThings 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
reference.cpp 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
light-city 提交于 2020-03-03 11:13 . update
//
// Created by light on 19-12-14.
//
#include <iostream>
#include <functional>
using namespace std;
// xvalue
int&& f(){
return 3;
}
struct As
{
int i;
};
As&& ff(){
return As();
}
int main() {
// lvalue
int x = 0;
cout << "(x).addr = " << &x << endl;
cout << "(x = 1).addr = " << &(x = 1) << endl;
cout << "(++x).addr = " << &++x << endl;
cout << "(cout << ' ').addr=" << &(cout << ' ') << endl;
cout << "(\"hello\").addr=" << &("hello") << endl;
// rvalue
cout<<true<<endl;
// xvalue
f(); // The expression f() belongs to the xvalue category, because f() return type is an rvalue reference to object type.
static_cast<int&&>(7); // The expression static_cast<int&&>(7) belongs to the xvalue category, because it is a cast to an rvalue reference to object type.
std::move(7); // std::move(7) is equivalent to static_cast<int&&>(7).
ff().i; // The expression f().i belongs to the xvalue category, because As::i is a non-static data member of non-reference type, and the subexpression f() belongs to the xvlaue category.
return 0;
}
C++
1
https://gitee.com/lzhenya/CPlusPlusThings.git
git@gitee.com:lzhenya/CPlusPlusThings.git
lzhenya
CPlusPlusThings
CPlusPlusThings
master

搜索帮助