mercredi 19 septembre 2018

Get string by const reference

std::string f(){
   return "xx";
}

int main(){

const std::string& ref = f();
// use ref
}

f returns temporary string by value. main "catch" it by const reference. Is it ok in C++?

Aucun commentaire:

Enregistrer un commentaire