移动局部变量没问题,但是移动它的局部变量地址一定是编译时错误?为什么我没有收到错误信息?

问题描述 投票:0回答:0

我正在观看 herb sutter cpp2 的视频,其中说移动局部变量的地址是 C++ 中的编译时错误,但是当我尝试移动局部变量的地址时,我没有收到错误,请解释我他想说什么。

herb sutter 视频链接

我写的在线演示

#include <iostream>

void f(std::string* s)
{
    *s = "jit";
}

void fun(std::string s)
{
    if (0) {
        f(std::move(&s));
    }
    else 
        f(std::move(&s));
}

int main()
{
    std::string s = "hi";
    fun(s);
}
c++ move move-semantics
© www.soinside.com 2019 - 2024. All rights reserved.