相关疑难解决方法(0)

什么是移动语义?

我刚刚听完了Scott Meyers关于C++ 0x的软件工程电台播客采访.大多数新功能对我来说都很有意义,我现在对C++ 0x感到兴奋,除了一个.我仍然没有得到移动语义 ......它们究竟是什么?

c++ c++-faq move-semantics c++11

1614
推荐指数
11
解决办法
39万
查看次数

了解返回值优化和返回临时值 - C++

请考虑三个功能.

std::string get_a_string()
{
    return "hello";
}

std::string get_a_string1()
{
    return std::string("hello");
}

std::string get_a_string2()
{
    std::string str("hello");
    return str;
}
Run Code Online (Sandbox Code Playgroud)
  1. RVO是否适用于所有三种情况?
  2. 可以在上面的代码中返回一个临时的吗?我相信它没关系,因为我按值返回它而不是返回任何引用它.

有什么想法吗?

c++ compiler-construction return-value-optimization

23
推荐指数
2
解决办法
4714
查看次数