C++11: Do move semantics get involved for pass by value?

后端 未结 2 1160
天命终不由人
天命终不由人 2021-01-05 00:50

I\'ve got an API that looks like this:

void WriteDefaultFileOutput(std::wostream &str, std::wstring target)
{
    //Some code that modifies target before         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-05 01:36

    "Pass by value" can mean either copy or move; if the argument is an lvalue, the copy constructor is invoked. If the argument is an rvalue, the move constructor is invoked. You don't have to do anything special involving rvalue references to get move semantics with pass by value.

    I dig deeper into this topic in What are move semantics?

提交回复
热议问题