小编phi*_*inn的帖子

C++ 右值参数

我写这个代码:

#include <iostream>
using namespace std;
class Foo
{

public:
    int a = 0;
    Foo()
    {
        cout << "ctor: " << this << endl;

    }
    ~Foo() {
       cout << "dtor: " << this << endl;
    }
};

Foo f()
{
    Foo foo;
    cout << "f " << &foo << endl;
    return foo;
}
void ff(Foo &&ffoo)
{
    cout << "ff " << &ffoo << endl;

}

int main()
{
    ff(f());
    std::cout << "Hello World!\n";
}
Run Code Online (Sandbox Code Playgroud)

输出看起来不错:

ctor: 0x7ffeda89bd7c
f 0x7ffeda89bd7c …
Run Code Online (Sandbox Code Playgroud)

c++ rvalue

12
推荐指数
1
解决办法
216
查看次数

标签 统计

c++ ×1

rvalue ×1