I am a beginner in cpp so excuse me for this question.
I was reading that returning const val prevents move semantics. therefore I dont understand why the following code is compiled and works normally. is it because only temporary object is being created? in what cases the move semantics cannot being done? thank you in advance!
#include <iostream>
using namespace std;
const string foo()
{
return string("hello");
}
int main()
{
string other = std::move(foo());
}
Aucun commentaire:
Enregistrer un commentaire